Repository navigation
Fix encodeInto() stopping short under ENABLE_FAST_TEXTENCODER - #8224
Conversation
There was a problem hiding this comment.
Superseded by the review of
2f854ce5.
This review, of e55a3783
✅ Approved — This is a small, correct fix to the autogated encodeInto() fit calculation, and the tests cover it well. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The surrogate-boundary and two-byte-range fixes in findBestFit() are correct, and the tests are thorough.
📝 Documentation: ✅ LGTM
The updated comments describe the code as it is now.
Reviewed commit: e55a3783
e55a378 to
2f854ce
Compare
There was a problem hiding this comment.
Superseded by the review of
3dfda325.
This review, of 2f854ce5
✅ Approved — This is a small, correct fix to the autogated encodeInto() fit calculation, and the tests cover it well. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The surrogate-boundary and two-byte-range fixes in findBestFit() are correct, and the tests are thorough.
📝 Documentation: ✅ LGTM
The updated comments describe the code as it is now.
Reviewed commit: 2f854ce5 — same changes as e55a3783, so this is that commit's review (no new review was run; line numbers are as of e55a3783)
findBestFit(), which decides how much of the input encodeInto() converts
under the ENABLE_FAST_TEXTENCODER autogate, could stop before code
points that fit, for two reasons:
- It measures the input in chunks with simdutf and adds their lengths.
A chunk could end between the halves of a surrogate pair, and
measured apart, each half counts as U+FFFD: six bytes instead of four.
'\u{1F639}'.repeat(1000) into 1001 bytes read 498 code units, not 500.
A chunk no longer ends on a lead surrogate.
- simpleUtfEncodingLength(), which measures the last few code units,
counted U+0400 to U+07FF (Cyrillic, Hebrew, Arabic, ...) as three
bytes instead of two. 'ж'.repeat(10) into 2 bytes read nothing, so
a caller encoding into a 2-byte buffer in a loop made no progress.
The result was always valid UTF-8, just shorter than the Encoding
Standard requires. The new bestFit tests check long runs of pairs and
of two-byte characters at every buffer size, and
encodeIntoFillsTheDestination checks encodeInto() itself.
Compatibility: no compatibility flag. The change affects only the
autogated path, and makes it return what the default path and the
standard do.
2f854ce to
3dfda32
Compare
There was a problem hiding this comment.
✅ Approved — This is a small, correct fix to the autogated encodeInto() fit calculation, and the tests cover it well. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The surrogate-boundary and two-byte-range fixes in findBestFit() are correct, and the tests are thorough.
📝 Documentation: ✅ LGTM
The updated comments describe the code as it is now.
Reviewed commit: 3dfda325 — same changes as e55a3783, so this is that commit's review (no new review was run; line numbers are as of e55a3783)
findBestFit(), which decides how much of the input encodeInto() converts under the ENABLE_FAST_TEXTENCODER autogate, could stop before code points that fit, for two reasons:
The result was always valid UTF-8, just shorter than the Encoding Standard requires. The new bestFit tests check long runs of pairs and of two-byte characters at every buffer size, and
encodeIntoFillsTheDestination checks encodeInto() itself.
Compatibility: no compatibility flag. The change affects only the autogated path, and makes it return what the default path and the standard do.
I've confirmed the autogate is not enabled, so users can't be relying on this buggy behavior yet.