Skip to content

fallback: count buffer bytes independently of memoryview shape - #753

Open
zhechen-cs wants to merge 1 commit into
msgpack:mainfrom
zhechen-cs:codex/count-memoryview-bytes
Open

zhechen-cs wants to merge 1 commit into
msgpack:mainfrom
zhechen-cs:codex/count-memoryview-bytes

Conversation

@zhechen-cs

Copy link
Copy Markdown

The fallback sizes its unpackb limits with len(packed) and checks incoming feeds with len(view). For a multidimensional memoryview, that is the first dimension rather than the byte count. A six-byte message reshaped to (2, 3) fails to unpack with a spurious length error, while feeding it can exceed max_buffer_size without raising BufferFull. A zero-dimensional view raises TypeError on Python 3.12.

Normalize input to a contiguous, one-dimensional byte view before computing lengths. Contiguous input is cast without copying; non-contiguous input uses the byte copy already needed by feed. Decoding remains unchanged. Tests cover several shapes, non-contiguous multidimensional input, scalar views, exact-fit feeds, and preserving the stream after an oversized feed is rejected.

Validation on macOS arm64, CPython 3.12:

  • All six new cases fail on the unmodified fallback and pass on the unmodified C extension.
  • After the fix: fallback full suite 148 passed, 4 skipped; C extension full suite 151 passed, 1 skipped.
  • PyPy 3.11: 138 passed, 5 skipped with test/test_except.py excluded. That unchanged module cannot be collected because this PyPy build does not provide _tracemalloc.
  • Ruff lint and format checks, and git diff --check, pass.

The existing thread_unsafe marker warning also occurs on the base. Other platforms have not been tested locally.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant