weida-http-codec 0.1.0-alpha.17

HTTP/1.1, HPACK, HTTP/2 framing, QPACK and HTTP/3 framing, sans-I/O
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//! Deterministic hostile-input smoke tests.
//!
//! The always-on companion to the `cargo fuzz` targets under
//! `crates/http/weida-http-codec/fuzz`: the same properties, driven by a
//! seeded xorshift generator so they run on stable Rust in the unit tier, with
//! no nightly toolchain and no corpus.
//!
//! The properties:
//!
//! 1. **Decoding never panics.** An error is only ever a return value.
//! 2. **An accepted input re-encodes to octets that decode to the same
//!    value.**
//! 3. **Every proper prefix of a valid input is `Incomplete`**
//!    (`fuzz_smoke_prefixes`), so a reader that gets a violation knows the
//!    peer is wrong and not merely slow.
//!
//! The generator builds well-formed inputs and then mutates a few octets, so
//! the decoders see both valid input and input one edit away from it; each
//! test asserts a minimum acceptance rate, so a generator that stops reaching
//! the decoder fails rather than passing vacuously.

use weida_http_codec::fields::Field;
use weida_http_codec::h1::{self, Chunk, ChunkedDecoder, RequestHead, ResponseHead};
use weida_http_codec::h2::{self, Frame};
use weida_http_codec::h3::{self, frame};
use weida_http_codec::hpack;
use weida_http_codec::uri::Target;
use weida_http_codec::{DecodeError, Limits, qpack};

const ITERATIONS: usize = 100_000;

/// Small, so that the caps are reached by a few dozen octets.
const LIMITS: Limits = Limits {
    max_head_bytes: 512,
    max_fields: 8,
    max_chunk_line: 32,
    max_frame_size: 16_384,
};

/// Deterministic xorshift64* generator: no dependency, reproducible failures.
pub struct Rng(u64);

impl Rng {
    pub fn new(seed: u64) -> Self {
        Self(seed | 1)
    }

    pub fn next(&mut self) -> u64 {
        self.0 ^= self.0 >> 12;
        self.0 ^= self.0 << 25;
        self.0 ^= self.0 >> 27;
        self.0.wrapping_mul(0x2545_f491_4f6c_dd1d)
    }

    pub fn below(&mut self, n: usize) -> usize {
        (self.next() % n as u64) as usize
    }

    pub fn pick<'a, T>(&mut self, items: &'a [T]) -> &'a T {
        &items[self.below(items.len())]
    }

    pub fn bytes(&mut self, alphabet: &[u8], max: usize) -> Vec<u8> {
        let n = self.below(max + 1);
        (0..n).map(|_| *self.pick(alphabet)).collect()
    }

    /// Up to three random edits: flip, insert or delete an octet.
    pub fn mutate(&mut self, mut v: Vec<u8>) -> Vec<u8> {
        for _ in 0..self.below(4) {
            let at = self.below(v.len() + 1);
            match self.below(3) {
                0 if at < v.len() => v[at] = self.next() as u8,
                1 => v.insert(at, *self.pick(b"\r\n :\t\0\x7fA/;")),
                2 if at < v.len() => {
                    v.remove(at);
                }
                _ => {}
            }
        }
        v
    }
}

const TOKEN: &[u8] = b"abcXYZ-_09!~";
const VALUE: &[u8] = b"abc XYZ09,;=\"\t\x80";

fn fields(rng: &mut Rng) -> Vec<u8> {
    let mut out = Vec::new();
    for _ in 0..rng.below(6) {
        let mut name = rng.bytes(TOKEN, 8);
        if name.is_empty() {
            name.push(b'x');
        }
        out.extend_from_slice(&name);
        out.extend_from_slice(b":");
        out.extend_from_slice(rng.pick(&[&b" "[..], b"", b"\t"]));
        out.extend_from_slice(&rng.bytes(VALUE, 12));
        out.extend_from_slice(rng.pick(&[&b"\r\n"[..], b"\n"]));
    }
    out
}

pub fn request(rng: &mut Rng) -> Vec<u8> {
    let mut out = Vec::new();
    out.extend_from_slice(rng.pick(&[&b""[..], b"", b"\r\n"]));
    out.extend_from_slice(rng.pick(&[&b"GET"[..], b"POST", b"HEAD", b"PATCH", b"X-Y"]));
    out.push(b' ');
    out.extend_from_slice(rng.pick(&[&b"/"[..], b"/a?b=c", b"*", b"http://h/p"]));
    out.push(b' ');
    out.extend_from_slice(rng.pick(&[&b"HTTP/1.1"[..], b"HTTP/1.0"]));
    out.extend_from_slice(b"\r\n");
    out.extend_from_slice(&fields(rng));
    out.extend_from_slice(b"\r\n");
    out
}

pub fn response(rng: &mut Rng) -> Vec<u8> {
    let mut out = Vec::new();
    out.extend_from_slice(rng.pick(&[&b"HTTP/1.1 "[..], b"HTTP/1.0 "]));
    out.extend_from_slice(rng.pick(&[&b"200 OK"[..], b"204", b"404 Not Found", b"999 x", b"100 "]));
    out.extend_from_slice(b"\r\n");
    out.extend_from_slice(&fields(rng));
    out.extend_from_slice(b"\r\n");
    out
}

pub fn chunked(rng: &mut Rng) -> (Vec<u8>, Vec<u8>) {
    let mut wire = Vec::new();
    let mut body = Vec::new();
    for _ in 0..rng.below(4) {
        let data = rng.bytes(b"ab\r\n0", 20);
        if data.is_empty() {
            continue;
        }
        body.extend_from_slice(&data);
        wire.extend_from_slice(format!("{:x}", data.len()).as_bytes());
        wire.extend_from_slice(rng.pick(&[&b""[..], b";ext=1", b" ;x"]));
        wire.extend_from_slice(b"\r\n");
        wire.extend_from_slice(&data);
        wire.extend_from_slice(b"\r\n");
    }
    wire.extend_from_slice(b"0\r\n");
    wire.extend_from_slice(&fields(rng));
    wire.extend_from_slice(b"\r\n");
    (wire, body)
}

fn pairs<'a>(fields: &'a [Field<'a>]) -> Vec<(&'a [u8], &'a [u8])> {
    fields.iter().map(|f| (f.name, f.value)).collect()
}

/// Decodes a whole chunked body; `Ok` holds the body and the trailers'
/// re-encoding input, `Err` the first error.
fn run_chunked(input: &[u8]) -> Result<(Vec<u8>, usize, usize), DecodeError> {
    let mut d = ChunkedDecoder::new();
    let mut pos = 0;
    let mut body = Vec::new();
    loop {
        let (chunk, used) = d.step(&input[pos..], LIMITS)?;
        assert!(used > 0 && pos + used <= input.len());
        pos += used;
        match chunk {
            Chunk::Data(data) => {
                assert!(!data.is_empty());
                body.extend_from_slice(data);
            }
            Chunk::End(trailers) => {
                assert!(trailers.len() <= LIMITS.max_fields);
                return Ok((body, trailers.len(), pos));
            }
        }
    }
}

/// Re-encodes an accepted request head and decodes it again. The re-encoding
/// is the canonical form (CRLF line endings, `name: value`, `HTTP/1.1`) and
/// may be longer than the input it came from, so it is decoded under a cap
/// of its own length.
fn roundtrip_request(head: &RequestHead<'_>) {
    let mut out = Vec::new();
    h1::encode_request_head(head.method, head.target, &pairs(&head.fields), &mut out)
        .expect("an accepted head re-encodes");
    let limits = Limits {
        max_head_bytes: out.len(),
        ..LIMITS
    };
    let (again, again_used) = h1::decode_request(&out, limits).expect("the re-encoding decodes");
    assert_eq!(again_used, out.len());
    assert_eq!(
        (again.method, again.target, &again.fields),
        (head.method, head.target, &head.fields)
    );
}

/// As [`roundtrip_request`] for a response head.
fn roundtrip_response(head: &ResponseHead<'_>) {
    let mut out = Vec::new();
    h1::encode_response_head(
        head.minor,
        head.status,
        head.reason,
        &pairs(&head.fields),
        &mut out,
    )
    .expect("an accepted head re-encodes");
    let limits = Limits {
        max_head_bytes: out.len(),
        ..LIMITS
    };
    let (again, _) = h1::decode_response(&out, limits).expect("the re-encoding decodes");
    assert_eq!(&again, head);
}

#[test]
fn fuzz_smoke_h1_request() {
    let mut rng = Rng::new(0x5eed_0001);
    let mut accepted = 0;
    for _ in 0..ITERATIONS {
        let input = request(&mut rng);
        let input = rng.mutate(input);
        let Ok((head, used)) = h1::decode_request(&input, LIMITS) else {
            continue;
        };
        accepted += 1;
        assert!(used <= input.len() && used <= LIMITS.max_head_bytes);
        assert!(head.fields.len() <= LIMITS.max_fields);
        roundtrip_request(&head);
    }
    assert!(accepted > ITERATIONS / 5, "only {accepted} accepted");
}

#[test]
fn fuzz_smoke_h1_response() {
    let mut rng = Rng::new(0x5eed_0002);
    let mut accepted = 0;
    for _ in 0..ITERATIONS {
        let input = response(&mut rng);
        let input = rng.mutate(input);
        let Ok((head, used)) = h1::decode_response(&input, LIMITS) else {
            continue;
        };
        accepted += 1;
        assert!(used <= input.len());
        roundtrip_response(&head);
        let _ = h1::response_framing(b"GET", head.status, &head.fields);
    }
    assert!(accepted > ITERATIONS / 5, "only {accepted} accepted");
}

/// A head of exactly [`LIMITS`]`.max_head_bytes` octets with the most fields
/// allowed, in bare-LF lines and `name:value` form.
fn head_at_cap(first_line: &[u8]) -> Vec<u8> {
    let mut input = first_line.to_vec();
    input.push(b'\n');
    for _ in 1..LIMITS.max_fields {
        input.extend_from_slice(b"b:1\n");
    }
    input.extend_from_slice(b"a:");
    input.resize(LIMITS.max_head_bytes - 2, b'x');
    input.extend_from_slice(b"\n\n");
    input
}

/// Nightly #417's `h1_response` crash, reduced: a head accepted at the cap
/// re-encodes longer than the cap (each bare LF becomes CRLF, each
/// `name:value` becomes `name: value`), and the round trip still holds.
#[test]
fn fuzz_smoke_h1_canonical_form_outgrows_the_cap() {
    let input = head_at_cap(b"HTTP/1.0 100");
    let (head, used) = h1::decode_response(&input, LIMITS).expect("accepted at the cap");
    assert_eq!(used, LIMITS.max_head_bytes);
    roundtrip_response(&head);

    let input = head_at_cap(b"GET / HTTP/1.0");
    let (head, used) = h1::decode_request(&input, LIMITS).expect("accepted at the cap");
    assert_eq!(used, LIMITS.max_head_bytes);
    roundtrip_request(&head);
}

#[test]
fn fuzz_smoke_chunked() {
    let mut rng = Rng::new(0x5eed_0003);
    let mut accepted = 0;
    for i in 0..ITERATIONS {
        let (wire, body) = chunked(&mut rng);
        if i % 2 == 0 {
            let (decoded, _, used) = run_chunked(&wire).expect("a generated body decodes");
            assert_eq!(decoded, body);
            assert_eq!(used, wire.len());
            accepted += 1;
        } else {
            let wire = rng.mutate(wire);
            let _ = run_chunked(&wire);
        }
    }
    assert!(accepted > 0);
}

#[test]
fn fuzz_smoke_uri() {
    let mut rng = Rng::new(0x5eed_0004);
    let mut accepted = 0;
    for _ in 0..ITERATIONS {
        let mut input = Vec::new();
        input.extend_from_slice(rng.pick(&[&b"http://"[..], b"HTTPS://", b"https://"]));
        input.extend_from_slice(rng.pick(&[
            &b"example.com"[..],
            b"[::1]",
            b"10.0.0.1",
            b"a-b.c",
            b"",
        ]));
        input.extend_from_slice(rng.pick(&[&b""[..], b":8080", b":443", b":", b":99999"]));
        input.extend_from_slice(&rng.bytes(b"/?#a=&%20b", 12));
        let input = rng.mutate(input);
        let Ok(text) = core::str::from_utf8(&input) else {
            continue;
        };
        let Ok(t) = Target::parse(text) else {
            continue;
        };
        accepted += 1;
        assert!(t.path_and_query.starts_with('/'));
        assert!(!t.path_and_query.contains('#'));
        assert_ne!(t.port, 0);
        let rebuilt = format!(
            "{}://{}{}",
            t.scheme.as_str(),
            t.authority(),
            t.path_and_query
        );
        assert_eq!(Target::parse(&rebuilt).expect("a rebuilt URL parses"), t);
    }
    assert!(accepted > ITERATIONS / 10, "only {accepted} accepted");
}

fn assert_incomplete<T: core::fmt::Debug>(r: Result<T, DecodeError>, input: &[u8]) {
    assert!(
        matches!(r, Err(DecodeError::Incomplete { .. })),
        "{:?}: {r:?}",
        String::from_utf8_lossy(input)
    );
}

#[test]
fn fuzz_smoke_prefixes() {
    let mut rng = Rng::new(0x5eed_0005);
    for _ in 0..ITERATIONS / 100 {
        let input = request(&mut rng);
        if h1::decode_request(&input, LIMITS).is_ok() {
            for cut in 0..input.len() {
                assert_incomplete(h1::decode_request(&input[..cut], LIMITS), &input[..cut]);
            }
        }
        let input = response(&mut rng);
        if h1::decode_response(&input, LIMITS).is_ok() {
            for cut in 0..input.len() {
                assert_incomplete(h1::decode_response(&input[..cut], LIMITS), &input[..cut]);
            }
        }
        let (wire, _) = chunked(&mut rng);
        for cut in 0..wire.len() {
            assert_incomplete(run_chunked(&wire[..cut]), &wire[..cut]);
        }
    }
}

#[test]
fn fuzz_smoke_hpack() {
    let mut rng = Rng::new(0x5eed_0006);
    // One encoder and decoder pair across every block, so the dynamic table
    // fills, evicts and is resized; a mutated copy of each block goes to a
    // fresh decoder.
    let mut enc = hpack::Encoder::new();
    let mut dec = hpack::Decoder::new(4096);
    let names: &[&[u8]] = &[
        b":path",
        b"x-a",
        b"cookie",
        b"accept",
        b"content-type",
        b"x-long-name",
    ];
    let mut accepted = 0;
    for i in 0..ITERATIONS / 10 {
        if i % 97 == 0 {
            let size = [0, 64, 256, 4096][rng.below(4)];
            enc.set_peer_max_table_size(size);
            dec.set_max_table_size(4096);
        }
        let list: Vec<(Vec<u8>, Vec<u8>, bool)> = (0..rng.below(6))
            .map(|_| {
                let name = rng.pick(names).to_vec();
                let value = rng.bytes(b"abc/09 =;", 16);
                (name, value, rng.below(8) == 0)
            })
            .collect();
        let fields: Vec<_> = list
            .iter()
            .map(|(n, v, s)| (n.as_slice(), v.as_slice(), *s))
            .collect();
        let mut block = Vec::new();
        enc.encode(&fields, &mut block);
        let mut out = Vec::new();
        dec.decode(&block, Limits::DEFAULT, &mut out)
            .expect("our own block decodes");
        let expect: Vec<_> = list
            .iter()
            .map(|(n, v, _)| (n.clone(), v.clone()))
            .collect();
        assert_eq!(out, expect);

        let mutated = rng.mutate(block);
        let mut out = Vec::new();
        if hpack::Decoder::new(4096)
            .decode(&mutated, LIMITS, &mut out)
            .is_err()
        {
            continue;
        }
        accepted += 1;
        assert!(out.len() <= LIMITS.max_fields);
        let fields: Vec<_> = out
            .iter()
            .map(|(n, v)| (n.as_slice(), v.as_slice(), false))
            .collect();
        let mut again = Vec::new();
        hpack::Encoder::new().encode(&fields, &mut again);
        let mut back = Vec::new();
        hpack::Decoder::new(4096)
            .decode(&again, LIMITS, &mut back)
            .expect("the re-encoding decodes");
        assert_eq!(back, out);
    }
    assert!(accepted > ITERATIONS / 100, "only {accepted} accepted");
}

fn h2_frame(rng: &mut Rng, payload: &[u8]) -> Vec<u8> {
    let stream = [0u32, 1, 3, 0x7fff_ffff][rng.below(4)];
    let code = rng.next() as u32;
    let frame = match rng.below(10) {
        0 => Frame::Data {
            stream,
            end_stream: rng.below(2) == 0,
            data: payload,
        },
        1 => Frame::Headers {
            stream,
            end_stream: false,
            end_headers: true,
            block: payload,
        },
        2 => Frame::Priority { stream },
        3 => Frame::RstStream { stream, code },
        4 => Frame::Settings {
            ack: false,
            params: (0..rng.below(4))
                .map(|_| {
                    (
                        rng.below(8) as u16,
                        [0, 1, 16_384, 65_535, 1 << 31][rng.below(5)],
                    )
                })
                .collect(),
        },
        5 => Frame::PushPromise {
            stream,
            promised: 2,
            end_headers: true,
            block: payload,
        },
        6 => Frame::Ping {
            ack: rng.below(2) == 0,
            data: *b"pingpong",
        },
        7 => Frame::GoAway {
            last_stream: stream,
            code,
            debug: payload,
        },
        8 => Frame::WindowUpdate {
            stream,
            increment: rng.next() as u32 & 0x7fff_ffff,
        },
        _ => Frame::Continuation {
            stream,
            end_headers: false,
            block: payload,
        },
    };
    let mut out = Vec::new();
    frame.encode(&mut out);
    out
}

#[test]
fn fuzz_smoke_h2_frame() {
    let mut rng = Rng::new(0x5eed_0007);
    let max = 64;
    let mut accepted = 0;
    for _ in 0..ITERATIONS {
        let payload = rng.bytes(b"\x00\x01\x08\xffab", 80);
        let wire = h2_frame(&mut rng, &payload);
        let wire = rng.mutate(wire);
        let Ok((frame, used)) = Frame::decode(&wire, max) else {
            continue;
        };
        accepted += 1;
        let declared = u32::from_be_bytes([0, wire[0], wire[1], wire[2]]);
        assert!(declared <= max);
        assert_eq!(used, h2::HEADER_LEN + declared as usize);
        if matches!(frame, Frame::Unknown { .. }) {
            continue;
        }
        let mut out = Vec::new();
        frame.encode(&mut out);
        let (again, again_used) = Frame::decode(&out, max).expect("the re-encoding decodes");
        assert_eq!((again, again_used), (frame, out.len()));
    }
    assert!(accepted > ITERATIONS / 10, "only {accepted} accepted");
}

#[test]
fn fuzz_smoke_qpack() {
    let mut rng = Rng::new(0x5eed_0008);
    let names: &[&[u8]] = &[
        b":path",
        b":method",
        b"x-a",
        b"authorization",
        b"accept",
        b"content-type",
    ];
    let mut accepted = 0;
    for _ in 0..ITERATIONS / 10 {
        let list: Vec<(Vec<u8>, Vec<u8>, bool)> = (0..rng.below(6))
            .map(|_| {
                let name = rng.pick(names).to_vec();
                let value = rng.bytes(b"GETab/*09 =;", 16);
                (name, value, rng.below(8) == 0)
            })
            .collect();
        let fields: Vec<_> = list
            .iter()
            .map(|(n, v, s)| (n.as_slice(), v.as_slice(), *s))
            .collect();
        let mut block = Vec::new();
        qpack::encode_field_section(&fields, &mut block);
        let mut out = Vec::new();
        qpack::decode_field_section(&block, Limits::DEFAULT, &mut out)
            .expect("our own section decodes");
        let expect: Vec<_> = list
            .iter()
            .map(|(n, v, _)| (n.clone(), v.clone()))
            .collect();
        assert_eq!(out, expect);

        let mutated = rng.mutate(block);
        let mut out = Vec::new();
        if qpack::decode_field_section(&mutated, LIMITS, &mut out).is_err() {
            continue;
        }
        accepted += 1;
        let fields: Vec<_> = out
            .iter()
            .map(|(n, v)| (n.as_slice(), v.as_slice(), false))
            .collect();
        let mut again = Vec::new();
        qpack::encode_field_section(&fields, &mut again);
        let mut back = Vec::new();
        qpack::decode_field_section(&again, LIMITS, &mut back).expect("the re-encoding decodes");
        assert_eq!(back, out);
    }
    assert!(accepted > ITERATIONS / 100, "only {accepted} accepted");
}

#[test]
fn fuzz_smoke_h3_frame() {
    let mut rng = Rng::new(0x5eed_0009);
    let mut accepted = 0;
    for _ in 0..ITERATIONS {
        let mut wire = Vec::new();
        if rng.below(2) == 0 {
            let settings: Vec<(u64, u64)> = (0..rng.below(4))
                .map(|i| ([1u64, 6, 7, 0x21][i], rng.next() >> (2 + rng.below(62))))
                .collect();
            h3::encode_settings(&settings, &mut wire).unwrap();
        } else {
            h3::encode_goaway(rng.next() >> (2 + rng.below(62)), &mut wire).unwrap();
        }
        let wire = rng.mutate(wire);
        let Ok((head, used)) = h3::decode_frame_header(&wire) else {
            continue;
        };
        let rest = &wire[used..];
        let Some(payload) = usize::try_from(head.len).ok().and_then(|n| rest.get(..n)) else {
            continue;
        };
        match head.kind {
            frame::SETTINGS => {
                let Ok(settings) = h3::decode_settings(payload, Limits::DEFAULT) else {
                    continue;
                };
                accepted += 1;
                let mut out = Vec::new();
                h3::encode_settings(&settings, &mut out).unwrap();
                let (_, used) = h3::decode_frame_header(&out).unwrap();
                assert_eq!(
                    h3::decode_settings(&out[used..], Limits::DEFAULT).unwrap(),
                    settings
                );
            }
            frame::GOAWAY => {
                let Ok(id) = h3::decode_goaway(payload) else {
                    continue;
                };
                accepted += 1;
                let mut out = Vec::new();
                h3::encode_goaway(id, &mut out).unwrap();
                let (_, used) = h3::decode_frame_header(&out).unwrap();
                assert_eq!(h3::decode_goaway(&out[used..]), Ok(id));
            }
            _ => {}
        }
    }
    assert!(accepted > ITERATIONS / 10, "only {accepted} accepted");
}