Skip to content

fix: decoder issues#3327

Merged
dnwe merged 2 commits intoIBM:mainfrom
hindessm:decoder-issues
Oct 2, 2025
Merged

fix: decoder issues#3327
dnwe merged 2 commits intoIBM:mainfrom
hindessm:decoder-issues

Conversation

@hindessm
Copy link
Copy Markdown
Collaborator

@hindessm hindessm commented Oct 2, 2025

Couple of issues spotted while debugging protocol message updates.

There was no check that there were sufficient remaining
bytes so bad messages could cause a panic in the
flexible/compact encoding case.

Signed-off-by: beanz <[email protected]>
@dnwe dnwe added the fix label Oct 2, 2025
@dnwe dnwe merged commit 9e0c1c2 into IBM:main Oct 2, 2025
17 checks passed
@hindessm hindessm deleted the decoder-issues branch October 3, 2025 06:58

switch {
case n < -1:
return 0, errInvalidStringLength
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤔 Duplicated testing, though here we’re only testing -1, below we test for the stronger < 0.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't recall any more but I probably wanted to keep it consistent with the non-flexible version. There are a few issues like this already that I'd like to tackle. For instance, when we get array lengths there are checks like:

	if tmp > rd.remaining() {
		rd.off = len(rd.raw)
		return -1, ErrInsufficientData
	} else if tmp > int(MaxResponseSize) {
		return -1, errInvalidArrayLength
	}

The second check is redundant since we know the total buffer size is less than MaxResponseSize as it was check after we read the length in the header the data arrived in so the remaining check covers it already.
The remaining check would be better made by the caller since we may need to check for, for example, 4*tmp (for int32 array) or 8*tmp (for int64 array). Checking 1*tmponly makes sense in the compact string case and even then it is potentially a significant underestimate.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm… those checks ought to probably be inverted anyways. Returning an invalid array length has value above simply returning insufficient data. 🤔

And yeah, checking the remaining for an array… 🤔 maybe we could pass in a byte size, allowing us to properly check for insufficient data. But as you say… maybe better to just do the check downstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants