Budget the raw graph fallback used by schema 5; legacy schemas keep their established reader. The same conservative budget is checked before writing.
(payload: &[u8])
| 317 | /// Budget the raw graph fallback used by schema 5; legacy schemas keep their |
| 318 | /// established reader. The same conservative budget is checked before writing. |
| 319 | pub fn decode(payload: &[u8]) -> FormatResult<GraphSectionPayload> { |
| 320 | if payload.len() > MAX { |
| 321 | return Err(FormatError::GraphFieldLimitExceeded); |
| 322 | } |
| 323 | let budget = Budget { |
| 324 | remaining: Cell::new(ALLOC - 512), |
| 325 | exceeded: Cell::new(false), |
| 326 | }; |
| 327 | let mut decoder = postcard::Deserializer::from_bytes(payload); |
| 328 | let result = GraphSectionPayload::deserialize(Guard { |
| 329 | inner: &mut decoder, |
| 330 | b: &budget, |
| 331 | depth: 0, |
| 332 | }); |
| 333 | let graph = match result { |
| 334 | Ok(g) => g, |
| 335 | Err(_) if budget.exceeded.get() => return Err(FormatError::GraphFieldLimitExceeded), |
| 336 | Err(e) => return Err(e.into()), |
| 337 | }; |
| 338 | if !decoder.finalize()?.is_empty() { |
| 339 | return Err(invalid("trailing raw graph bytes")); |
| 340 | } |
| 341 | Ok(graph) |
| 342 | } |
| 343 | |
| 344 | #[cfg(test)] |
| 345 | mod tests { |