Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/pcapkit/protocols/application/httpv2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ below:
======= ========= ===================== ==========================
Octets Bits Name Description
======= ========= ===================== ==========================
0 0 ``http.length`` Length
0 0 ``http.length`` Payload Length
3 24 ``http.type`` Type
4 32 ``http.flags`` Flags
5 40 Reserved
Expand Down
29 changes: 14 additions & 15 deletions pcapkit/protocols/application/httpv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
======= ========= ===================== ==========================
Octets Bits Name Description
======= ========= ===================== ==========================
0 0 ``http.length`` Length
0 0 ``http.length`` Payload Length
3 24 ``http.type`` Type
4 32 ``http.flags`` Flags
5 40 Reserved
Expand Down Expand Up @@ -290,12 +290,11 @@ def read(self, length: 'Optional[int]' = None, **kwargs: 'Any') -> 'Data_HTTP':
# than it claims report a length nothing backs (e.g. a nine-octet buffer
# declaring 16777215). ``length`` is the number of octets actually
# available for this frame (``Protocol.__len__`` returns
# ``len(self._data)``, and an explicit ``length`` means the same), so
# both have to clear the minimum header size *and* the declared value
# must not exceed what is available. This library's convention (see
# ``_make_http_length``) is that ``length`` counts the whole frame,
# header included, so the two are directly comparable.
if schema.length < 9 or length < 9 or schema.length > length:
# ``len(self._data)``, and an explicit ``length`` means the same), so it
# has to clear the 9-octet header *and* back the declared value. The
# declared value counts the frame payload only, the header excluded
# (:rfc:`9113#section-4.1`), so ``length`` must hold both.
if length < 9 or schema.length + 9 > length:
raise ProtocolError(f'HTTP/2: [Type {schema.type}] invalid format')
if schema.type in (Enum_Frame.SETTINGS, Enum_Frame.PING) and schema.stream['sid'] != 0:
raise ProtocolError(f'HTTP/2: [Type {schema.type}] invalid format')
Expand Down Expand Up @@ -364,7 +363,7 @@ def make(self, # type: ignore[override]
for bit in range(8):
flags_val[f'bit_{bit}'] = (int(flags) & (1 << bit)) >> bit

length = self._make_http_length(frame_val, flags) + 9
length = self._make_http_length(frame_val, flags)

return Schema_HTTP(
length=length,
Expand Down Expand Up @@ -634,7 +633,7 @@ def _read_http_priority(self, schema: 'Schema_PriorityFrame', *,
ProtocolError: If the packet is malformed.

"""
if header.length != 9:
if header.length != 5:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

data = Data_PriorityFrame(
Expand Down Expand Up @@ -677,7 +676,7 @@ def _read_http_rst_stream(self, schema: 'Schema_RSTStreamFrame', *,
ProtocolError: If the packet is malformed.

"""
if header.length != 13:
if header.length != 4:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

data = Data_RSTStreamFrame(
Expand Down Expand Up @@ -721,7 +720,7 @@ def _read_http_settings(self, schema: 'Schema_SettingsFrame', *,
ProtocolError: If the packet is malformed.

"""
if (header.length - 9) % 6 != 0 or header.stream['sid'] != 0:
if header.length % 6 != 0 or header.stream['sid'] != 0:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

flag = Data_SettingsFrameFlags(
Expand All @@ -731,7 +730,7 @@ def _read_http_settings(self, schema: 'Schema_SettingsFrame', *,
'__value__': schema.__flags__,
})

if flag.ACK and header.length - 9 != 0:
if flag.ACK and header.length != 0:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

sets = OrderedMultiDict() # type: OrderedMultiDict[Enum_Setting, int]
Expand Down Expand Up @@ -782,7 +781,7 @@ def _read_http_push_promise(self, schema: 'Schema_PushPromiseFrame', *,
ProtocolError: If the packet is malformed.

"""
if header.length < 13:
if header.length < 4:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

flag = Data_PushPromiseFrameFlags(
Expand Down Expand Up @@ -836,7 +835,7 @@ def _read_http_ping(self, schema: 'Schema_PingFrame', *,
ProtocolError: If the packet is malformed.

"""
if header.length != 17:
if header.length != 8:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

flag = Data_PingFrameFlags(
Expand Down Expand Up @@ -925,7 +924,7 @@ def _read_http_window_update(self, schema: 'Schema_WindowUpdateFrame', *,
ProtocolError: If the packet is malformed.

"""
if header.length != 13:
if header.length != 4:
raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')

data = Data_WindowUpdateFrame(
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/protocols/data/application/httpv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Flags(Data):
class HTTP(Protocol):
"""Data model for HTTP/2 protocol."""

#: Length.
#: Length of the frame payload, the 9-octet header excluded.
length: 'int'
#: Frame type.
type: 'Frame'
Expand Down
2 changes: 1 addition & 1 deletion pcapkit/protocols/schema/application/httpv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def http_frame_selector(pkt: 'dict[str, Any]') -> 'Field':
class HTTP(Schema):
"""Header schema for HTTP/2 packet."""

#: Length.
#: Length of the frame payload, the 9-octet header excluded.
length: 'int' = NumberField(length=3, signed=False)
#: Frame type.
type: 'Enum_Frame' = EnumField(length=1, namespace=Enum_Frame)
Expand Down
Loading
Loading