shashank created CAMEL-26903:
--------------------------------

             Summary: camel-hl7 - HL7 MLLP MINA decoder fails with a negative 
length when an end byte 1 comes right before the start byte
                 Key: CAMEL-26903
                 URL: https://issues.apache.org/jira/browse/CAMEL-26903
             Project: Camel
          Issue Type: Bug
          Components: camel-hl7
            Reporter: shashank
            Assignee: shashank


Named as a follow-up in the PR of CAMEL-26433 (maxFrameLength for the MINA 
codec), which also made the decoder compare the bytes unsigned (on main only).

{{HL7MLLPDecoder}} keeps the previous byte to find the end bytes (end byte 1, 
then end byte 2). A start byte, and end bytes that come before any start byte 
(which the decoder ignores with a WARN), do not reset that previous byte. So 
when an end byte 1 comes before the start byte ({{\x1c\x0b\r...}}, or an 
ignored end {{\x1c\r}} followed by {{\x0b\r...}}), an end byte 2 right after 
the start byte (the first segment separator of a message that begins with an 
empty segment) is taken as the end of a message of two bytes, whose length 
without the start and end bytes is negative. The decoder then fails with an 
{{IllegalArgumentException}} ("fieldSize cannot be negative") with 
{{produceString=true}}, or a {{NegativeArraySizeException}} for a byte array, 
and the MINA consumer closes the session of that sender.

*Proposal*
Reset the previous byte when a start byte starts a message (to a value that no 
byte has, so a configured end byte 1 of {{0x00}} is not matched either), with 
tests at the decoder level for the byte sequences above.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to