{"record":{"id":"996f3571f996d79e","repo":"apache/hadoop","slug":"attempted-to-seek-or-read-past-the-end-of-the-file-996f35","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-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/store/ByteBufferInputStream.java","lineNumber":110,"sourceCode":"  }\n\n  public synchronized int read() throws IOException {\n    if (available() > 0) {\n      return byteBuffer.get() & 0xFF;\n    } else {\n      return -1;\n    }\n  }\n\n  @Override\n  public synchronized long skip(long offset) 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(FSExceptionMessages.CANNOT_SEEK_PAST_EOF);\n    }\n    byteBuffer.position((int) newPos);\n    return newPos;\n  }\n\n  @Override\n  public synchronized int available() {\n    checkOpenState();\n    return byteBuffer.remaining();\n  }\n\n  /**\n   * Get the current buffer position.\n   * @return the buffer position\n   */\n  public synchronized int position() {\n    checkOpenState();\n    return byteBuffer.position();","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/store/ByteBufferInputStream.java#L92-L128","documentation":"skip(offset) throws EOFException('Attempted to seek or read past the end of the file') when position() + offset exceeds the buffer size. Skipping exactly to size is allowed; one byte more is not. The check is explicit because the stream is bounded by the wrapped ByteBuffer.","triggerScenarios":"skip(size + 1 - position()) or any skip whose result exceeds the buffer size; skipping to footer offsets computed from a stale or different file length.","commonSituations":"Readers that skip to a footer/trailer offset obtained from a different file version; using skip() to probe EOF; lengths computed against a truncated or replaced buffer.","solutions":["Clamp the skip to the remaining bytes: long n = Math.min(offset, in.available())","Compare position() + offset against the buffer size (or use hasRemaining()) before skipping","Treat EOFException here as a normal end-of-data signal in probing readers"],"exampleFix":"// before\nin.skip(offset); // throws when position()+offset > size\n\n// after\nlong n = Math.min(offset, in.available());\nif (n > 0) {\n  in.skip(n);\n}","handlingStrategy":"validation","validationCode":"long maxSkip = Math.min(requested, in.available()); // clamps to remaining\nif (maxSkip > 0) {\n  in.skip(maxSkip);\n}","typeGuard":null,"tryCatchPattern":"Catch EOFException from skip() as an end-of-data signal in probing readers; recompute offsets against the current buffer size rather than a cached length.","preventionTips":["Always clamp skips with available()","Re-read file size right before skipping to footers","Treat EOFException from skip as data-end, not as an error to retry"],"tags":["hadoop","io","input-stream","seek","eof"],"backgroundTag":"seek-past-eof","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}