Skip to content

Bound map size hints by remaining payload - #308

Open
jadenfix wants to merge 1 commit into
jamesmunns:mainfrom
jadenfix:fix/map-size-hint-payload-limit
Open

jadenfix wants to merge 1 commit into
jamesmunns:mainfrom
jadenfix:fix/map-size-hint-payload-limit

Conversation

@jadenfix

Copy link
Copy Markdown

Addresses the MapAccess portion of #307 in both postcard and postcard2.

Both map deserializers currently return the claimed entry count directly as their size hint. With the three-byte input [0xc0, 0x84, 0x3d], deserializing a HashMap<u8, u8> requests a 3,145,736-byte allocation before returning the expected input error. Apply the same conservative remaining-payload check already used by SeqAccess: omit an impossible hint without rejecting the map itself.

The regressions cover the malformed input and valid maps with zero-byte unit entries. A standalone public-API consumer with a recording system allocator confirms that the large reservation becomes zero in both versions; Vec and BTreeMap controls remain unchanged. Both new regressions fail on the base commit and pass here.

Validation: the complete ci.sh passed locally (195 tests; workspace checks and strict Clippy; both thumb configurations and the RISC-V no-atomics configuration; formatting; nightly documentation with warnings denied). The exact final commit also received independent agent source review and a separate run of both focused regressions.

This deliberately leaves the unknown-length reader-flavor part of #307 unchanged and does not claim to prevent every allocation from malformed input. Codex assisted with implementation and validation; the independent review described above is agent review, not maintainer or human approval.

A corrupt map length can make alloc-backed visitors reserve megabytes before reading any key. Match the existing sequence guard in postcard and postcard2: omit the hint when known remaining payload bytes are fewer than the claimed entries.

This does not reject zero-byte unit entries or change unknown-length reader hints. Public allocator probes and regressions cover the malformed-input case and valid unit maps. Addresses the map gap in jamesmunns#307.
@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
🔨 Latest commit 200d1b2
🔍 Latest deploy log https://app.netlify.com/projects/cute-starship-2d9c9b/deploys/6ad4c3345154bc128649a3c9

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