GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — Fix the region copied by Unpooled.copiedBuffer(CharSequence, int, int, Charset) by Marti2203 · Pull Request #17971 · netty/netty Conversation
Contributor
Motivation: When the Modification:
Result:
Reproduction on 4.2 (5776ebc): CharBuffer cb = CharBuffer.wrap("hello world"); // hasArray() == false Unpooled.copiedBuffer(cb, 2, 5, CharsetUtil.US_ASCII); // "llo" (a String gives "llo w") Unpooled.copiedBuffer(cb, 6, 5, CharsetUtil.US_ASCII); // IllegalArgumentException: newPosition > limit: (6 > 5) With this change they return This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…, Charset)
Motivation:
When the CharSequence is a CharBuffer without an accessible array, for
example one returned by CharBuffer.wrap(CharSequence) or
asReadOnlyBuffer(), copiedBuffer(string, offset, length, charset) sets
the limit of the slice to length instead of offset + length. The result
is truncated for any offset > 0: CharBuffer.wrap("hello world") with
offset 2 and length 5 gives "llo" instead of "llo w", and offset 6
throws IllegalArgumentException. The array-backed CharBuffer and the
String paths copy the requested region.
Modifications:
- Set the limit of the slice to offset + length.
- Add a test with array-backed and non array-backed CharBuffers.
Result:
copiedBuffer(CharSequence, int, int, Charset) copies the requested
region for every CharBuffer.
normanmaurer
approved these changes
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
normanmaurer
pushed a commit
that referenced
this pull request
…uence, int, int, Charset) (#17995) Auto-port of #17971 to 4.1 Cherry-picked commit: 19e950b --- Motivation: When the `CharSequence` passed to `Unpooled.copiedBuffer(CharSequence, int offset, int length, Charset)` is a `CharBuffer` without an accessible array, for example one returned by `CharBuffer.wrap(CharSequence)` or `asReadOnlyBuffer()`, the method sets the limit of the slice to `length` instead of `offset + length`. The result is truncated for any `offset > 0`, or `IllegalArgumentException` is thrown if `offset > length`. The array-backed `CharBuffer` and `String` paths copy the requested region. Modification: - Set the limit of the slice to `offset + length`. - Add `UnpooledTest.testCopiedBufferCharBufferRegion`, which covers array-backed and non array-backed `CharBuffer`s, with position 0 and a non-zero position. Result: `copiedBuffer(CharSequence, int, int, Charset)` copies the requested region for every `CharBuffer`. Co-authored-by: Martin Mirchev <[email protected]>
normanmaurer
pushed a commit
that referenced
this pull request
…uence, int, int, Charset) (#17996) Auto-port of #17971 to 5.0 Cherry-picked commit: 19e950b --- Motivation: When the `CharSequence` passed to `Unpooled.copiedBuffer(CharSequence, int offset, int length, Charset)` is a `CharBuffer` without an accessible array, for example one returned by `CharBuffer.wrap(CharSequence)` or `asReadOnlyBuffer()`, the method sets the limit of the slice to `length` instead of `offset + length`. The result is truncated for any `offset > 0`, or `IllegalArgumentException` is thrown if `offset > length`. The array-backed `CharBuffer` and `String` paths copy the requested region. Modification: - Set the limit of the slice to `offset + length`. - Add `UnpooledTest.testCopiedBufferCharBufferRegion`, which covers array-backed and non array-backed `CharBuffer`s, with position 0 and a non-zero position. Result: `copiedBuffer(CharSequence, int, int, Charset)` copies the requested region for every `CharBuffer`. Co-authored-by: Martin Mirchev <[email protected]>
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
…uence, int, int, Charset) (netty#17995) Auto-port of netty#17971 to 4.1 Cherry-picked commit: 19e950b --- Motivation: When the `CharSequence` passed to `Unpooled.copiedBuffer(CharSequence, int offset, int length, Charset)` is a `CharBuffer` without an accessible array, for example one returned by `CharBuffer.wrap(CharSequence)` or `asReadOnlyBuffer()`, the method sets the limit of the slice to `length` instead of `offset + length`. The result is truncated for any `offset > 0`, or `IllegalArgumentException` is thrown if `offset > length`. The array-backed `CharBuffer` and `String` paths copy the requested region. Modification: - Set the limit of the slice to `offset + length`. - Add `UnpooledTest.testCopiedBufferCharBufferRegion`, which covers array-backed and non array-backed `CharBuffer`s, with position 0 and a non-zero position. Result: `copiedBuffer(CharSequence, int, int, Charset)` copies the requested region for every `CharBuffer`. Co-authored-by: Martin Mirchev <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | |||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |