GCP: Fix GCSInputStream.readTail partial read returning short count#16894
Draft
thswlsqls wants to merge 1 commit into
Draft
GCP: Fix GCSInputStream.readTail partial read returning short count#16894thswlsqls wants to merge 1 commit into
thswlsqls wants to merge 1 commit into
Conversation
readTail called the private read() helper once, and that helper does a single readChannel.read(buffer). A GCS NIO channel may return fewer bytes than requested even when more data remains, so readTail could return a short count and leave the tail partially read. This breaks the RangeReadable.readTail contract. Loop the channel read until the requested length is filled or EOF is reached, matching S3InputStream and ADLSInputStream which already loop via IOUtil.readRemaining. GCS uses a ReadChannel rather than an InputStream, so it needs a channel-based loop instead. Generated-by: Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GCSInputStream.readTailcalls the privateread()helper once, which does a singlereadChannel.read(buffer). A GCS NIOReadChannelmay return fewer bytes than requested even when more data remains, soreadTailcan return a short count — violating theRangeReadable.readTailcontract to return the actual number of bytes read.S3InputStream.readTailandADLSInputStream.readTailalready loop viaIOUtil.readRemaining; GCS uses aReadChannelrather than anInputStream, so it needs a channel-based loop instead.readTailchanges (readFullyis a separate concern).Testing done
TestGCSInputStream#testReadTailPartialRead: a Mockito mockReadChannelfills the buffer in two partial reads; assertsreadTailreturns the full length with the expected bytes../gradlew :iceberg-gcp:checkpassed (test, spotlessCheck, checkstyle, errorProne). GCP is not a revapi module.