Skip to content

fix(tftp): keep request options when serializing into a reused datagram buffer - #424

Open
simpleqt wants to merge 1 commit into
apache:masterfrom
simpleqt:fix/tftp-buffered-request-options
Open

simpleqt wants to merge 1 commit into
apache:masterfrom
simpleqt:fix/tftp-buffered-request-options

Conversation

@simpleqt

@simpleqt simpleqt commented Nov 15, 2026 •

Copy link
Copy Markdown

TFTPRequestPacket.newDatagram(DatagramPacket, byte[]) serializes a request into a reusable buffer, but it set the datagram length to fileLength + modeLength + 3, without the option extensions. TFTP.bufferedSend() sends through that path with its long-lived sendBuffer, so a read/write request that carries options (blksize, timeout, tsize, ...) was sent truncated: the options were written into the buffer but the datagram length stopped before them.

The options were only correct when the caller happened to use newDatagram() (which allocates exactly the right size) or when the reused buffer still had zero bytes after the mode string, which is why the bug was invisible until the buffer was reused.

The fix counts the option extensions once (getOptionsLength()), includes them in the setLength call in the buffered path, and writes the terminating NUL explicitly instead of relying on the buffer already containing zero.

Test

TFTPRequestPacketTest.testNewDatagramBufferIncludesOptions parses a read request with options, fills a reused buffer with a non-zero sentinel, serializes into it through the buffered overload and asserts both the datagram length and the buffer bytes match the packet built by newDatagram().

  • with the source change reverted: mvn -B -o -ntp -Dtest=TFTPRequestPacketTest test -> 3 run, 1 failure, expected: <30> but was: <17>
  • with the change: same command -> 3 run, 0 failures; mvn -B -o -ntp -Dtest='TFTP*Test' test -> 33 run, 0 failures

The commit carries an Assisted-By: trailer.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

TFTPRequestPacket.newDatagram(DatagramPacket, byte[]) computed the datagram length without the encoded option extensions, so a request parsed with options and forwarded through TFTP.bufferedSend() lost its options. Count the option extensions once and write their trailing NUL terminator explicitly.

Assisted-By: DeepSeek Harness (deepseek-v41-flash)
@simpleqt
simpleqt force-pushed the fix/tftp-buffered-request-options branch from 0951b2f to b6f9b70 Compare November 16, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants