Skip to content

CacheBufferedIndexInput should throw EOFException #53975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DaveCTurner
Copy link
Contributor

InputStream#read may return -1 if it reaches EOF. This is unexpected in a
CacheBufferedIndexInput but may happen if, for instance, the underlying file
is truncated. Today we don't handle this specially and an EOF can cause strange
behaviour, often throwing an ArrayIndexOutOfBoundsException. This commit adds
better handling for EOF by throwing an EOFException.

InputStream#read may return -1 if it reaches EOF. This is unexpected in a
`CacheBufferedIndexInput` but may happen if, for instance, the underlying file
is truncated. Today we don't handle this specially and an EOF can cause strange
behaviour, often throwing an `ArrayIndexOutOfBoundsException`. This commit adds
better handling for EOF by throwing an `EOFException`.
@DaveCTurner DaveCTurner added >non-issue :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Mar 23, 2020
@DaveCTurner DaveCTurner requested a review from tlrx March 23, 2020 13:26
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore)

throw new EOFException(String.format(Locale.ROOT,
"unexpected EOF reading [%d-%d] ([%d] bytes remaining) from %s", start, end, remaining, cacheFileReference));
}
System.arraycopy(copyBuffer, 0, buffer, offset + bytesCopied, bytesRead);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces len with bytesRead in case of a partial read. I think this was technically ok before since we would proceed to overwrite the junk bytes with correct ones, but it was confusing.

@DaveCTurner DaveCTurner merged commit 47ec08d into elastic:feature/searchable-snapshots Mar 25, 2020
@DaveCTurner DaveCTurner deleted the 2020-03-23-eof-exceptions branch March 25, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants