Repository navigation
Fix RCE: refuse object-dtype arrays in msgpack deserialization - #49
Merged
Merged
Conversation
msgpack_numpy.decode calls pickle.loads on object-dtype ('O') numpy
arrays. m.patch() makes it the global msgpack object_hook, so any
msgpack.unpackb in the process runs pickle.loads on such an array.
pickle.loads runs arbitrary code, so an untrusted payload (for example
an uploaded .ocd design) could execute code during unpack, before any
class allowlist check. The patched reader also wraps a caller-supplied
object_hook and runs decode first, so a hook cannot make unpack safe.
Capture the unpatched msgpack.unpackb before m.patch(), then re-override
msgpack.unpackb/loads with a safe reader that refuses object-dtype
arrays and delegates all other maps (numeric/void arrays, complex
numbers, plain dicts) to the normal decoder. Writing (packb) is
unchanged. No cell design uses object-dtype arrays (verified against the
OpenCell database: 45895 arrays, all numeric, zero object arrays), so
the refusal breaks no real design.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0.2.24 is already on PyPI and is now used by PR #48. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
msgpack_numpy.decode calls pickle.loads on object-dtype ('O') numpy arrays. m.patch() makes it the global msgpack object_hook, so any msgpack.unpackb in the process runs pickle.loads on such an array. pickle.loads runs arbitrary code, so an untrusted payload (for example an uploaded .ocd design) could execute code during unpack, before any class allowlist check. The patched reader also wraps a caller-supplied object_hook and runs decode first, so a hook cannot make unpack safe.
Capture the unpatched msgpack.unpackb before m.patch(), then re-override msgpack.unpackb/loads with a safe reader that refuses object-dtype arrays and delegates all other maps (numeric/void arrays, complex numbers, plain dicts) to the normal decoder. Writing (packb) is unchanged. No cell design uses object-dtype arrays (verified against the OpenCell database: 45895 arrays, all numeric, zero object arrays), so the refusal breaks no real design.