{"record":{"id":"6087190e33cdbbe7","repo":"apache/hadoop","slug":"attempted-to-seek-or-read-past-the-end-of-the-file-608719","errorCode":null,"errorMessage":"Attempted to seek or read past the end of the file","messagePattern":"Attempted to seek or read past the end of the file","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSDataBlocks.java","lineNumber":716,"sourceCode":"\n      public synchronized int read() {\n        if (available() > 0) {\n          return byteBuffer.get() & OBSCommonUtils.BYTE_TO_INT_MASK;\n        } else {\n          return -1;\n        }\n      }\n\n      @Override\n      public synchronized long skip(final long offset)\n          throws IOException {\n        verifyOpen();\n        long newPos = position() + offset;\n        if (newPos < 0) {\n          throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK);\n        }\n        if (newPos > size) {\n          throw new EOFException(\n              FSExceptionMessages.CANNOT_SEEK_PAST_EOF);\n        }\n        byteBuffer.position((int) newPos);\n        return newPos;\n      }\n\n      @Override\n      public synchronized int available() {\n        Preconditions.checkState(byteBuffer != null,\n            FSExceptionMessages.STREAM_IS_CLOSED);\n        return byteBuffer.remaining();\n      }\n\n      /**\n       * Get the current buffer position.\n       *\n       * @return the buffer position\n       */","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSDataBlocks.java#L698-L734","documentation":"The second positional check in ByteBufferInputStream.skip(): if position() + offset exceeds the block's fixed size, the method throws EOFException(FSExceptionMessages.CANNOT_SEEK_PAST_EOF). It fires when a skip request tries to move the read cursor beyond the end of the buffered block data. Like the negative variant, it is a pure client-side bounds check on the in-memory bytebuffer block — the stream never consults OBS.","triggerScenarios":"Calling skip(n) with n larger than remaining bytes in the block (position + n > size); seeking forward past a small final block during upload buffering; a reader loop that assumes skip() silently stops at EOF and instead lets the exception propagate.","commonSituations":"Record readers that skip fixed-size headers/records against short blocks; code ported from FSDataInputStream.skip() semantics (which clamps at EOF) to raw block streams; arithmetic bugs where remaining length is computed against the wrong total.","solutions":["Bound the skip by remaining bytes: skip only min(requested, stream.size() - stream.position())","Treat EOFException from skip as a signal that the block is exhausted and exit the read loop gracefully","Prefer read()-based skipping (loop reading into a small buffer) when the exact remaining length is uncertain"],"exampleFix":"// before\nblockStream.skip(requested); // throws if it passes the end of the block\n\n// after\nlong canSkip = Math.min(requested, blockStream.size() - blockStream.position());\nif (canSkip > 0) {\n  blockStream.skip(canSkip);\n}","handlingStrategy":"validation","validationCode":"long remaining = blockStream.size() - blockStream.position();\nlong toSkip = Math.min(requested, remaining);\nif (toSkip > 0) {\n  blockStream.skip(toSkip);\n}","typeGuard":null,"tryCatchPattern":"try {\n  blockStream.skip(requested);\n} catch (EOFException e) {\n  if (FSExceptionMessages.CANNOT_SEEK_PAST_EOF.equals(e.getMessage())) {\n    // treat as end of block: consume the rest and signal EOF to the caller\n    blockStream.skip(blockStream.size() - blockStream.position());\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always bound skips by size() - position()","Prefer read-based skipping when remaining length is unknown","Handle EOFException from skip as a normal end-of-data signal in reader loops"],"tags":["positioning","eof","io","hadoop-obs"],"backgroundTag":"seek-past-eof","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}