Skip to content
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

The method getNativeBuffer() in DefaultDataBuffer returns misconfigured ByteBuffer #30967

Closed
access-control-rtfm opened this issue Jul 31, 2023 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@access-control-rtfm
Copy link

access-control-rtfm commented Jul 31, 2023

Affects: 6.0.11


The class DefaultDataBuffer has method getNativeBuffer with follow implementation:

	public ByteBuffer getNativeBuffer() {
		this.byteBuffer.position(this.readPosition);
		this.byteBuffer.limit(readableByteCount());
		return this.byteBuffer;
	}

        @Override
	public int readableByteCount() {
		return this.writePosition - this.readPosition;
	}

The limit of the byte buffer to return should be set to the this.writePosition, because if the condition (this.writePosition - this.readPosition) <= this.readPosition is satisfied, the limit of the returned byte buffer will be equal to its current position, so no single byte could be read from this buffer, even if the condition this.writePosition > this.readPosition is satisfied. So how it should be:

	public ByteBuffer getNativeBuffer() {
		return this.byteBuffer.limit(this.writePosition).position(this.readPosition);
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 31, 2023
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 2, 2023
@sbrannen
Copy link
Member

sbrannen commented Aug 2, 2023

Thanks for reporting the issue. We'll look into it.

@injae-kim
Copy link
Contributor

I create fix PR #32009 with test~! 😃

@sbrannen sbrannen changed the title The method getNativeBuffer in the class DefaultDataBuffer returns misconfigured byte buffer The method getNativeBuffer() in DefaultDataBuffer returns misconfigured ByteBuffer Jan 30, 2024
@poutsma
Copy link
Contributor

poutsma commented Feb 7, 2024

You are correct, this is a bug. It does not seem to occur much because the read position is typically 0.

Even though this is a bug fix, it is a breaking change and breaks backward compatibility and therefore I am scheduling it for 6.2.

@poutsma poutsma added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 7, 2024
@poutsma poutsma added this to the 6.2.0-M1 milestone Feb 7, 2024
@bclozel bclozel changed the title The method getNativeBuffer() in DefaultDataBuffer returns misconfigured ByteBuffer The method getNativeBuffer() in DefaultDataBuffer returns misconfigured ByteBuffer Feb 14, 2024
poutsma added a commit that referenced this issue Feb 20, 2024
Change position and limit on duplicate, rather than source.

See gh-30967
Closes gh-32009
@izeye
Copy link
Contributor

izeye commented Mar 14, 2024

It seems that this or #30967 needs to be superseded not to have two entries for the same in the milestone or the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants