gh-155004: Fix iconv error handlers in a non-initial shift state - #155005
Open
serhiy-storchaka wants to merge 3 commits into
Open
gh-155004: Fix iconv error handlers in a non-initial shift state#155005serhiy-storchaka wants to merge 3 commits into
serhiy-storchaka wants to merge 3 commits into
Conversation
The replacement bytes are copied to the output as they are, so the output has to be back in the initial shift state first. Otherwise, in a stateful encoding such as ISO-2022-CN, they are read back as encoded data. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
GNU libiconv resolves ISO-2022-CN-EXT but rejects U+4E2D, so probing the character must not fail the test. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
An iconv() which substitutes an unencodable character instead of failing leaves the shift state, and the substitute is then dropped from the output. The descriptor and the output disagree after that, so the replacement bytes are written in a non-initial shift state. Seen with citrus iconv (FreeBSD: ISO-2022-KR and ISO-2022-CN) and libiconv (macOS: ISO-2022-JP). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The bytes an error handler returns are copied to the output as they are, so the output has to be back in the initial shift state first. It was reset only after the replacement, and with a NULL output buffer, so the closing sequence was never written and the replacement was read back as encoded data.
iconv_reset_shift_state()flushes into the output before the replacement is copied, and only when there is something to copy.iconv:ISO-2022-JPnow matchesiso2022_jpbyte for byte with all four error handlers.Encoding
<char>😀<char>and decoding it back was broken for 146 (encoding, handler) pairs of the 1180 encodingsiconv -llists here, and for none now. The test fails without the change.The iconv codecs are new in 3.16, so there is no NEWS entry.