Fix str_errors parameter regression in C extension (#255) #271
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.
Summary
Fixes #255 - Restores support for the
str_errorsparameter in the C extension when decoding CBOR strings containing invalid UTF-8 byte sequences. The parameter has been broken since v5.6.0.Problem Description
Since version 5.6.0, the
str_errorsparameter incbor2.loads()stopped working in the C extension (_cbor2). When decoding CBOR data containing invalid UTF-8 sequences:Expected behavior (v5.5.1 and earlier):
Broken behavior (v5.6.0 - v5.8.0):
The pure Python implementation (
cbor2._decoder) continued to work correctly; only the C extension was affected.Root Cause
Commit 387755e (PR #204) - "Fixed MemoryError when decoding large definite strings" Date: Jan 14, 2024
This commit rewrote the string decoding logic in
source/decoder.cto handle large strings in chunks, fixing memory issues. However, it accidentally removed thestr_errorsparameter from UTF-8 decoding calls:Before (v5.5.1 - working):
After (v5.6.0 - broken):
Changes
Re-add the missing parameter.
Fixes #255
Test Plan
Add a new unit test for this functionality.
Checklist
If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):
tests/) which would fail without your patchdocs/), in case of behavior changes or newfeatures
docs/versionhistory.rst).