Summary
TLVParser does not enforce the max_frames limit inherited from BaseParser and continues parsing frames beyond the configured threshold. BinaryFrameParser correctly stops parsing when the frame limit is reached, but TLVParser does not, leading to inconsistent behavior across parser implementations.
Reproduction
from sigflow.parsers.tlv import TLVParser
from sigflow.core.context import ExecutionContext
import struct
data = b""
for i in range(5):
data += struct.pack(">HH", i, 1) + b"A"
parser = TLVParser(max_frames=2)
frames = parser.parse(data, ExecutionContext({}))
print(len(frames))
Expected Behavior
Expected output: 2
the parser should have stopped after reaching the max_frame limit
Actual Behavior
Actual output:
Actual output:5
Parsing continued beyond the limit.
Environment
- Python version: 3.12.0
- sigflow version or commit: sigflow-0.1.0
- Operating system: Windows
Additional Context
During investigation, BaseParser was observed to define a configurable max_frames limit. BinaryFrameParser enforces this limit by stopping parsing and issuing a diagnostic warning when the threshold is reached.
However, TLVParser currently appears not to apply a similar check before appending frames. This results in behavior that differs across parser implementations. This may allow larger TLV streams to continue generating frames beyond the configured threshold, potentially increasing resource usage and bypassing the intended safeguard.
Summary
TLVParser does not enforce the max_frames limit inherited from BaseParser and continues parsing frames beyond the configured threshold. BinaryFrameParser correctly stops parsing when the frame limit is reached, but TLVParser does not, leading to inconsistent behavior across parser implementations.
Reproduction
from sigflow.parsers.tlv import TLVParser
from sigflow.core.context import ExecutionContext
import struct
data = b""
for i in range(5):
data += struct.pack(">HH", i, 1) + b"A"
parser = TLVParser(max_frames=2)
frames = parser.parse(data, ExecutionContext({}))
print(len(frames))
Expected Behavior
Expected output: 2
the parser should have stopped after reaching the max_frame limit
Actual Behavior
Actual output:
Actual output:5
Parsing continued beyond the limit.
Environment
Additional Context
During investigation, BaseParser was observed to define a configurable max_frames limit. BinaryFrameParser enforces this limit by stopping parsing and issuing a diagnostic warning when the threshold is reached.
However, TLVParser currently appears not to apply a similar check before appending frames. This results in behavior that differs across parser implementations. This may allow larger TLV streams to continue generating frames beyond the configured threshold, potentially increasing resource usage and bypassing the intended safeguard.