apache/hadoop · error · EOFException

Attempted to seek or read past the end of the file

Error message

Attempted to seek or read past the end of the file

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/store/ByteBufferInputStream.java:110

  }

  public synchronized int read() throws IOException {
    if (available() > 0) {
      return byteBuffer.get() & 0xFF;
    } else {
      return -1;
    }
  }

  @Override
  public synchronized long skip(long offset) throws IOException {
    verifyOpen();
    long newPos = position() + offset;
    if (newPos < 0) {
      throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK);
    }
    if (newPos > size) {
      throw new EOFException(FSExceptionMessages.CANNOT_SEEK_PAST_EOF);
    }
    byteBuffer.position((int) newPos);
    return newPos;
  }

  @Override
  public synchronized int available() {
    checkOpenState();
    return byteBuffer.remaining();
  }

  /**
   * Get the current buffer position.
   * @return the buffer position
   */
  public synchronized int position() {
    checkOpenState();
    return byteBuffer.position();

View on GitHub (pinned to 2add963021)

Solutions

  1. Clamp the skip to the remaining bytes: long n = Math.min(offset, in.available())
  2. Compare position() + offset against the buffer size (or use hasRemaining()) before skipping
  3. Treat EOFException here as a normal end-of-data signal in probing readers

Example fix

// before
in.skip(offset); // throws when position()+offset > size

// after
long n = Math.min(offset, in.available());
if (n > 0) {
  in.skip(n);
}
Defensive patterns

Strategy: validation

Validate before calling

long maxSkip = Math.min(requested, in.available()); // clamps to remaining
if (maxSkip > 0) {
  in.skip(maxSkip);
}

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/996f3571f996d79e. Report an issue: GitHub.