| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Store actual byte lengths in format metadata instead of allocated slot sizes, so retrieval extracts exact data without relying on null-termination. Use byte count instead of character count for str slot allocation to prevent multi-byte UTF-8 overflow.
|
The following commit authors need to sign the Contributor License Agreement: |
Sorry, something went wrong.
|
Both of the PRs are active so you shouldn't create a new one. And if this PR is generated by LLM, please read this: https://devguide.python.org/getting-started/generative-ai/ |
Sorry, something went wrong.
|
Closing in favor of #145266, which covers the same root cause and fix approach (stored byte lengths in format metadata, removing rstrip(b'\x00')). I'll contribute tests and review there. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
ShareableList has two data corruption bugs, both rooted in the same design flaw: C-style null-terminated storage semantics applied to length-delimited Python types.
Bug 1 — UTF-8 underallocation (#145261, #88336): Slot allocation uses len(item) (character count) instead of byte count for str items. Multi-byte UTF-8 strings overflow their allocated slot and corrupt adjacent data.
Bug 2 — Null stripping (#106939, #96779): The back-transform lambdas call rstrip(b'\x00') to remove struct padding, but this also strips legitimate trailing null bytes from user data.
Approach
Store actual byte lengths in the format metadata (separate from the allocated slot sizes used for struct.pack_into), and use those exact lengths during retrieval instead of relying on null-termination. This makes both bugs go away with a single conceptual change.
Specifically:
Cross-version compatibility
Tests
Prior work
This PR consolidates the approaches from #144559 (@aisk, null-stripping fix) and #145266 (@zetzschest, both fixes). Both PRs are open with zero reviews. The fixes belong together because they share the same root cause and the same solution mechanism (stored byte lengths in format metadata).
📚 Documentation preview 📚: https://cpython-previews--145488.org.readthedocs.build/