Skip to content

fix: correct length-coded number size for the 3-byte range - #4500

Merged
sidorares merged 2 commits into
sidorares:masterfrom
lazerg:fix/issue-4499-length-coded-number-off-by-one
Aug 24, 2026
Merged

fix: correct length-coded number size for the 3-byte range#4500
sidorares merged 2 commits into
sidorares:masterfrom
lazerg:fix/issue-4499-length-coded-number-off-by-one

Conversation

@lazerg

@lazerg lazerg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Packet.lengthCodedNumberLength() returns 5 for the 0xffff <= n < 0xffffff range, but writeLengthCodedNumber() only ever writes 4 bytes there (a 1-byte 0xfd marker plus a 3-byte Int24). Before #4494, packet sizes were measured with a real dry-run write, so this drift never surfaced. Since #4494 switched to computing sizes arithmetically from lengthCodedNumberLength(), any string/JSON/blob parameter whose encoded length falls in that range now throws COM_STMT_EXECUTE serialized N bytes, expected N+1. This fixes the length function to match what the writer actually emits.

Fixes #4499

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.53%. Comparing base (ca10232) to head (7b6ac9e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4500   +/-   ##
=======================================
  Coverage   92.53%   92.53%           
=======================================
  Files          93       93           
  Lines       15972    15972           
  Branches     2290     2290           
=======================================
  Hits        14780    14780           
  Misses       1192     1192           
Flag Coverage Δ
compression-0 92.15% <100.00%> (ø)
compression-1 92.51% <100.00%> (ø)
static-parser-0 91.35% <100.00%> (ø)
static-parser-1 91.47% <100.00%> (ø)
tls-0 92.10% <100.00%> (ø)
tls-1 92.53% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sidorares

Copy link
Copy Markdown
Owner

Thanks @lazerg ! Fix looks solid, thanks for catching the bug (which existed for long time, but recent change accidentally uncovered it). I added some integration tests in #4503

@sidorares
sidorares merged commit de56272 into sidorares:master Aug 24, 2026
104 checks passed
@sidorares

Copy link
Copy Markdown
Owner

@lazerg fix published as mysql@3.24.2

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Off-by-one in Packet.lengthCodedNumberLength() causes "COM_STMT_EXECUTE serialized N bytes, expected N+1" for string/JSON params >= 65535 bytes

2 participants