Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-141336: Fix Unicode escape assertion failure in error handler#141344

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mohsinm-dev wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
frommohsinm-dev:fix-unicode-escape-assertion-gh-141336

Conversation

@mohsinm-dev
Copy link
Contributor

@mohsinm-devmohsinm-dev commentedNov 10, 2025
edited by bedevere-appbot
Loading

Fixes assertion failure in Unicode escape decoding when using custom error handlers that return single-character replacements and rewind input position.

Root Cause

The issue occurs in unicode_decode_call_errorhandler_writer() when:

  1. Error handler returns a replacement string of length 1 (replen == 1)
  2. Error handler rewinds input position (increasing remaining input bytes)
  3. Original code failed to account for replacement length in buffer calculations

This led to assertion failures in debug builds.

Fix

  • Always include full replacement length in writer.min_length calculations
  • Change condition from replen > 1 to replen > 0
  • Add full replen instead of replen - 1 to maintain buffer invariant

Testing

  • Reproduction case now works without assertion failure
  • All codec callback tests pass (43/43)
  • Specific mutating decode handler test passes
  • No regressions detected in broader codec tests

Fixes#141336

When unicode_decode_call_errorhandler_writer() processes a replacementstring of length 1 and the error handler rewinds the input position(increasing remaining input), the original code failed to account forthe replacement length in writer.min_length calculations.This resulted in assertion failures when writer capacity was insufficientafter writing the replacement: assert(end - s <= writer.size - writer.pos).The fix ensures the full replacement length is always included inwriter.min_length, regardless of replacement size, maintaining thebuffer capacity invariant for all decoders using this error helper.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Assertion failure in Objects/unicodeobject.c_PyUnicode_DecodeUnicodeEscapeInternal2: Assertion 'end - s <= writer.size - writer.pos' failed

1 participant

@mohsinm-dev

[8]ページ先頭

©2009-2025 Movatter.jp