Title: Validate nanoseconds range when unpacking timestamps in the C extension by chuenchen309 · Pull Request #716 · msgpack/msgpack-python · GitHub
Open Graph Title: Validate nanoseconds range when unpacking timestamps in the C extension by chuenchen309 · Pull Request #716 · msgpack/msgpack-python
X Title: Validate nanoseconds range when unpacking timestamps in the C extension by chuenchen309 · Pull Request #716 · msgpack/msgpack-python
Description: The C extension's unpack_timestamp() decodes the nanoseconds field of a timestamp64/timestamp96 but never range-checks it, so with timestamp=1|2|3 it silently accepts a malformed value ≥ 1,000,000,000: >>> import msgpack, struct >>> b = b"\xd7\xff" + struct.pack("!Q", (10**9 << 34)) # timestamp64, ns = 1e9 >>> msgpack.unpackb(b, timestamp=1) # C ext, float mode 1.0 # accepted, time-shifted ~1s >>> msgpack.unpackb(b, timestamp=0) # C ext, default Timestamp mode ValueError: ... # correctly rejected Three signals agree this is a bug, not lenient parsing: The wire spec: "In timestamp 64 and timestamp 96 formats, nanoseconds must not be larger than 999999999." The pure-Python fallback (Timestamp.__init__) already rejects it in every mode. The C extension itself rejects the identical bytes at timestamp=0 (which routes through Timestamp); only the 1/2/3 fast paths skip validation. The fix adds the range check inside unpack_timestamp() so all modes reject consistently, matching the fallback and the spec. Valid nanoseconds (≤ 999999999) are unaffected. Added a regression test covering every timestamp= mode; full suite passes. Disclosure: this PR was authored by an AI coding agent (Claude Code) running on this account — it found the C-vs-fallback divergence, reproduced it, wrote the fix and the test, and wrote this description. The account holder reviews every change and is accountable for it, and the verification above is re-runnable from the diff. Happy to close it if it isn't the kind of contribution you want.
Open Graph Description: The C extension's unpack_timestamp() decodes the nanoseconds field of a timestamp64/timestamp96 but never range-checks it, so with timestamp=1|2|3 it silently accepts a malformed value ≥ 1,000,...
X Description: The C extension's unpack_timestamp() decodes the nanoseconds field of a timestamp64/timestamp96 but never range-checks it, so with timestamp=1|2|3 it silently accepts a malformed value ≥ 1,...
Opengraph URL: https://github.com/msgpack/msgpack-python/pull/716
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8b7ee606-c6a6-adeb-9c76-b707b3098bc8 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A29C:68F76:52618F:715145:6B07511B |
| html-safe-nonce | b3031f088154230e0f77640bca40a04209aae7af34bf7309ebb29681f794cddf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjlDOjY4Rjc2OjUyNjE4Rjo3MTUxNDU6NkIwNzUxMUIiLCJ2aXNpdG9yX2lkIjoiMTQ5MDk3NjUzNTQzNDcxMTMyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 194afedf8f3a9d33f6d8993d8711f9c46e9b73079a11e775d720b43cf412d1a7 |
| hovercard-subject-tag | pull_request:4086128733 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/msgpack/msgpack-python/pull/716/files |
| twitter:image | https://avatars.githubusercontent.com/u/48723787?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/48723787?s=400&v=4 |
| og:image:alt | The C extension's unpack_timestamp() decodes the nanoseconds field of a timestamp64/timestamp96 but never range-checks it, so with timestamp=1|2|3 it silently accepts a malformed value ≥ 1,000,... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 663b1a69a41309856ffd9403fa5b764f6c0f78a39a0a8f75fb2c205c96a947be |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/msgpack/msgpack-python git https://github.com/msgpack/msgpack-python.git |
| octolytics-dimension-user_id | 198264 |
| octolytics-dimension-user_login | msgpack |
| octolytics-dimension-repository_id | 2242705 |
| octolytics-dimension-repository_nwo | msgpack/msgpack-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2242705 |
| octolytics-dimension-repository_network_root_nwo | msgpack/msgpack-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | effa2c0a160a75bd95d9ffcc6320197d7aea0d83 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width