|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | """HTTP's version guess takes a bare frame for HTTP/2 only if a sender could write it. C.f. #1141. |
3 | 3 |
|
4 | | -Since #1138 an HTTP/2 frame's Length counts the payload alone |
5 | | -(:rfc:`9113#section-4.1`), so any nine octets whose Length fits the buffer are |
6 | | -self-consistent. :meth:`HTTP._guess_version |
| 4 | +An HTTP/2 frame's Length counts the payload alone (:rfc:`9113#section-4.1`, |
| 5 | +#1138), so any nine octets whose Length fits the buffer are self-consistent. |
| 6 | +:meth:`HTTP._guess_version |
7 | 7 | <pcapkit.protocols.application.http.HTTP._guess_version>` falls through to an |
8 | | -HTTP/2 trial parse when neither the preface nor an HTTP/1 start line matches, and |
9 | | -that trial accepted most zero-heavy binary: nine zero octets came back as |
10 | | -``HTTP/2 type=0``, a ``DATA`` frame on stream 0, which :rfc:`9113#section-6.1` |
11 | | -makes a protocol error. |
| 8 | +HTTP/2 trial parse when neither the preface nor an HTTP/1 start line matches. A |
| 9 | +trial that accepts any self-consistent header would take most zero-heavy binary: |
| 10 | +nine zero octets would come back as ``HTTP/2 type=0``, a ``DATA`` frame on stream |
| 11 | +0, which :rfc:`9113#section-6.1` makes a protocol error. |
12 | 12 |
|
13 | | -The guess now requires a frame type :rfc:`9113` defines, no flag that type |
| 13 | +The guess requires a frame type :rfc:`9113` defines, no flag that type |
14 | 14 | leaves undefined, a clear reserved bit, and a stream that type may be sent on. |
15 | | -Explicit ``version=2`` parsing is not affected, and is asserted unchanged here. |
| 15 | +Explicit ``version=2`` parsing is not subject to the guess, as asserted here too. |
16 | 16 |
|
17 | 17 | The legal frames in :data:`LEGAL_FRAMES` were built with Scapy 2.7.0's |
18 | 18 | :mod:`scapy.contrib.http2` (``H2Frame`` over each frame class) and are embedded |
|
70 | 70 | ('ORIGIN, not an RFC 9113 type', '0000000c0000000000'), |
71 | 71 | ) |
72 | 72 |
|
73 | | -#: The seeded fuzz. Pre-fix, this corpus produced 566 HTTP/2 labels, of which |
74 | | -#: 249 were ``DATA`` (most on stream 0) and 317 frames of unknown type. |
| 73 | +#: The seeded fuzz. Measured without the guess's checks, this corpus produced |
| 74 | +#: 566 HTTP/2 labels, of which 249 were ``DATA`` (most on stream 0) and 317 |
| 75 | +#: frames of unknown type. |
75 | 76 | FUZZ_SEED = 1141 |
76 | 77 | FUZZ_COUNT = 5000 |
77 | 78 | PRE_FIX_HTTP2_LABELS = 566 |
@@ -111,7 +112,7 @@ def test_nine_zero_octets_are_not_guessed_as_http2(self) -> None: |
111 | 112 | self._guess(bytes(9)) |
112 | 113 |
|
113 | 114 | def test_explicit_version_still_parses_nine_zero_octets(self) -> None: |
114 | | - """Explicit HTTP/2 parsing stays RFC-exact: only the guess is tightened.""" |
| 115 | + """Explicit HTTP/2 parsing is RFC-exact: the checks apply to the guess only.""" |
115 | 116 | from pcapkit.protocols.application.http import HTTP |
116 | 117 |
|
117 | 118 | http = HTTP(bytes(9), 9, version=2) |
|
0 commit comments