ppkarwasz opened a new pull request, #4518: URL: https://github.com/apache/logging-log4j2/pull/4518
Fixes #4517. Since #4336, `DatagramOutputStream` drops the whole datagram as soon as a `write` call does not fit in the 65,507 bytes allowed by IPv4, including the bytes already buffered. UDP is mostly used for RFC 5424 syslog messages, whose receivers must tolerate truncated messages, so this PR truncates the datagram instead: - `copy()` appends as many bytes as still fit, even in the middle of a `write` call, and counts the rest; - `flush()` always sends the buffered bytes and logs `UDP datagram truncated from N to 65507 bytes` at `WARN` level when something was cut; - the footer, appended last, is the first part to be cut. It also validates the range passed to `write(byte[], int, int)`, throwing `IndexOutOfBoundsException` with the same message as `Objects.checkFromIndexSize` on Java 9+ (`Range [off, off + len) out of bounds for length n`), through a private helper that works on Java 8. Since neither `2.27.0` nor `2.26.2` is released yet, the changelog entry of #4336 is updated instead of adding a new one. ## Tests `DatagramOutputStreamTest` is rewritten: - a payload written in 8 KiB chunks is cut inside the 8th chunk, and exactly the first 65,507 bytes are received; - a single oversized `write` is truncated on `close()`; - a small event sent after a truncated one arrives complete; - the footer is truncated first; - invalid ranges are rejected with the JDK message. All 10 tests pass on JDK 17 in every surefire execution of `log4j-core-test`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
