Skip to main content

Module nesting

Module nesting 

Source
Expand description

How deeply JSON may nest, checked before anything recursive touches it.

Reading JSON (serde_json) and walking it are recursive, so the stack they need grows with how deeply the text nests arrays and objects. On a laptop the stack is large and has a guard page. On a microcontroller it is a few kilobytes with nothing below it, and running off the end silently overwrites other memory. So the no_std build refuses any JSON text that nests deeper than NO_STD_MAX_NESTING levels, with a scan of the raw bytes that uses no recursion, before the text is parsed. Protocol objects nest about ten levels deep, so real credentials never come near it.

The std build keeps its existing limits (serde_json’s own 128 levels and the per-input limits elsewhere in the core), so nothing changes there.

Constants§

NO_STD_MAX_NESTING
The deepest JSON nesting the no_std build reads: [[1]] nests 2 levels.
TOO_DEEP
The text of the refusal for JSON nested past NO_STD_MAX_NESTING.

Functions§

check_value
Refuse a JSON value that nests past NO_STD_MAX_NESTING in a no_std build (a walk with its own stack, no recursion). For values the caller built or parsed itself.
parse
Parse JSON text into a Value, refusing text nested past NO_STD_MAX_NESTING in a no_std build before serde_json reads it. Firmware should read every JSON input it hands to the core with this.
too_deep
The refusal for JSON nested past NO_STD_MAX_NESTING.