Safe ByteBuffer array extraction#2892
Merged
Merged
Conversation
The old Compressor.byteBufferToArray had two bugs: the hasArray branch ignored position/limit, and the else branch mutated the buffer's position. Replace it with the safe internal.byteBufferToArray helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When the buffer has a backing array with offset 0, position 0, and remaining == array length, return the backing array directly (no copy). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace unsafe ByteBuffer.array() calls in BodyToHttpClient, MultipartBodyBuilder, FinagleBackend, and AbstractFetchBackend with the shared internal.byteBufferToArray helper. Remove the now-unused ByteBufferBackedInputStream class. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…alizing Use ByteBufferBackedInputStream(b.duplicate()) to stream ByteBuffer content lazily, avoiding eager materialization of potentially large buffers. The duplicate() preserves the original buffer's position. Also remove stale .claude/orca-system-prompt.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #2880
Summary
byteBufferToArrayhelper insttp.client4.internalthat correctly handles direct, read-only, partially-consumed, and slicedByteBuffers (preserves position/limit). For a fresh, full heap buffer the backing array is returned directly (no copy).ByteBuffer.array()calls across the codebase with the shared helper:DigestAuthenticator.calculateHa2(auth-int)testing.forceBodyAsString/forceBodyAsByteArrayinternal.enqueueBytesCompressor/defaultCompressorsBodyToHttpClientMultipartBodyBuilder(both non-stream and stream variants)FinagleBackendAbstractFetchBackendCompressor.byteBufferToArrayandAbstractFetchBackend.byteBufferToArrayByteBufferBackedInputStreamTest plan
ByteBufferToArrayTest— 7 cases covering direct, read-only, partial, sliced buffers, fast-path optimization, aliasing, and position preservationDigestAuthenticatorTest— auth-int digest with direct and partial byte buffersEnqueueBytesTest— direct and partial byte buffersForceBodyAsTest—forceBodyAsStringandforceBodyAsByteArraywith direct and partial buffers🤖 Generated with Claude Code