GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix out-of-bounds read when packing ext data with overridden __len__ by kitkatt7 · Pull Request #765 · msgpack/msgpack-python

Conversation

@kitkatt7

@kitkatt7 kitkatt7 commented Nov 2, 2026

Copy link
Copy Markdown

Packer takes the ext body pointer from the bytes object's buffer but its length from len(). A bytes subclass can override __len__, so the length no longer matches the pointer and msgpack_pack_raw_body copies past the end of the buffer. Both the ExtType branch of _pack_inner (reached by packb(ExtType(code, data))) and Packer.pack_ext_type(code, data) are affected. Packing ExtType(0x42, data) where data is a bytes subclass whose __len__ returns 4096 but whose real length is 2 reads 4094 bytes beyond the payload into the output.

Size the body with Py_SIZE of the same object instead of len(), matching the bytes branch just above it. The pure Python fallback is not affected: it writes the real bytes and cannot read out of bounds.

test_pack_ext_type_len_override is skipped under the pure-Python fallback like the other C-extension-only tests. It fails on the unmodified extension (emits an ext 16 header claiming 4096 bytes) and passes after the change. Full test/ passes under both the C extension and MSGPACK_PUREPYTHON=1; ruff check and format pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitkatt7
fix out-of-bounds read when packing ext data with overridden __len__
465b8d8
The ext packing paths took the body pointer from the bytes object but
its length from len(), which a bytes subclass can override, so
msgpack_pack_raw_body copied past the buffer. Size the body with Py_SIZE
of the same object in _pack_inner and pack_ext_type.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitkatt7
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.