| 436 | |
| 437 | #[test] |
| 438 | fn decode_rejects_a_body_over_the_limit() { |
| 439 | // Compress 5000 bytes, then demand it decode within 1000 — the streaming |
| 440 | // guard must reject it as TooLarge rather than allocating the full output. |
| 441 | let pack = SyncPack { |
| 442 | objects: vec![ObjectRecord::new( |
| 443 | ObjectFamily::Change, |
| 444 | "k", |
| 445 | vec![7u8; 5000], |
| 446 | )], |
| 447 | refs: vec![], |
| 448 | }; |
| 449 | let wire = pack.encode().unwrap(); |
| 450 | let err = decode_with_limit::<SyncPack>(&wire, 1000).unwrap_err(); |
| 451 | assert!(matches!(err, SyncError::TooLarge { limit: 1000 })); |
| 452 | } |
| 453 | |
| 454 | #[test] |
| 455 | fn decode_rejects_garbage() { |