Andrea Cosentino created CAMEL-26481:
----------------------------------------
Summary: camel-syslog: Rfc5425FrameDecoder should handle
fragmented length fields
Key: CAMEL-26481
URL: https://issues.apache.org/jira/browse/CAMEL-26481
Project: Camel
Issue Type: Improvement
Components: camel-syslog
Reporter: Andrea Cosentino
Assignee: Andrea Cosentino
Fix For: 4.24.0, 4.22.3, 4.18.6
h3. Current behaviour
In {{camel-syslog}}, {{Rfc5425FrameDecoder}} decodes octet-counting frames over
Netty TCP connections.
When incoming bytes end inside a length field before the space delimiter (for
instance when a TCP segment ends after frame content and contains only initial
digits of the next frame length):
* {{indexOf(in, ' ')}} returns {{-1}}.
* {{lengthbuffer}} remains empty, causing {{Integer.parseInt("")}} to throw a
{{NumberFormatException}}.
* The decoder catches the exception and executes {{in.resetReaderIndex()}}.
Because {{in.markReaderIndex()}} is not set after completing earlier frames,
{{in.resetReaderIndex()}} rewinds {{readerIndex}} back to index 0 of the Netty
cumulation buffer, causing the decoder to re-process and re-emit previously
decoded frames repeatedly.
Additionally, {{in.readBytes(index)}} allocates a buffer that is not released.
h3. Expected behaviour
{{Rfc5425FrameDecoder}} should verify that the space delimiter has arrived
before parsing the length field. If the delimiter has not arrived yet, it
should wait for additional data without modifying or resetting the reader
index. It should also read the length value without allocating unreleased
buffers.
h3. Change
* In {{Rfc5425FrameDecoder.decode}}:
- Check if the space delimiter is present before parsing the length field; if
absent, return immediately without altering {{readerIndex}}.
- Parse length digits directly from the buffer without allocating unreleased
{{ByteBuf}} instances.
- Advance {{readerIndex}} past the length and delimiter once confirmed.
* Add unit tests in {{camel-syslog}} verifying that fragmented streams ending
within length fields decode frames correctly in sequence.
h3. Tests
* Unit test in {{components/camel-syslog}} using {{EmbeddedChannel}} verifying
sequential decoding across fragmented stream chunks.
* Ensure all existing tests in {{camel-syslog}} continue to pass.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)