Skip to content

Fix bug with packet sizes - #559

Merged
davidrg merged 1 commit into
davidrg:masterfrom
jgoerzen:jgoerzen/packet-size-bugfix
Aug 8, 2026
Merged

Fix bug with packet sizes#559
davidrg merged 1 commit into
davidrg:masterfrom
jgoerzen:jgoerzen/packet-size-bugfix

Conversation

@jgoerzen

@jgoerzen jgoerzen commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This is an import of
OpenKermit/ckermit@d560c58

Original description:

The initial bug can be duplicated with this command, which will hang:

touch /tmp/foobar12345
kermit -H -Y -C "set host /network-type:pseudoterminal kermit -x, remote del /tmp/foobar12345, close, exit"

Note that the /tmp/foobar12345 filename is the precise length needed to trigger this.

When long packets are negotiated, kermit switches to long packet formatting (extended length) if the total packet size (excluding SOP and the LEN byte itself) exceeds the maximum length that can be represented as a single printable ASCII character in the short packet's LEN field.

Since short packet lengths are encoded via tochar(len) = len + 32, and the maximum printable ASCII character is '~' (126), the maximum value that can be encoded in the short LEN field is 126 - 32 = 94 bytes.

Any packet where (len + bctl + 2) exceeds 94 must be formatted as a long packet. The previous threshold of > 96 was incorrect and caused packets of size 95 and 96 to be formatted as short packets.

This resulted packes of size 95 or 96 generating a len byte of 127 (0x7f) or 128 (0x80), which the receiving end rejected.

This is an import of
OpenKermit/ckermit@d560c58

Original description:

The initial bug can be duplicated with this command, which will hang:

touch /tmp/foobar12345
kermit -H -Y -C "set host /network-type:pseudoterminal kermit -x, remote del /tmp/foobar12345, close, exit"

Note that the /tmp/foobar12345 filename is the precise length needed to
trigger this.

When long packets are negotiated, kermit switches to long
packet formatting (extended length) if the total packet size (excluding
SOP and the LEN byte itself) exceeds the maximum length that can be
represented as a single printable ASCII character in the short packet's
LEN field.

Since short packet lengths are encoded via tochar(len) = len + 32, and the
maximum printable ASCII character is '~' (126), the maximum value that
can be encoded in the short LEN field is 126 - 32 = 94 bytes.

Any packet where (len + bctl + 2) exceeds 94 must be formatted as a long
packet. The previous threshold of > 96 was incorrect and caused packets
of size 95 and 96 to be formatted as short packets.

This resulted packes of size 95 or 96 generating a len byte of
127 (0x7f) or 128 (0x80), which the receiving end rejected.
@davidrg
davidrg merged commit 3ca6724 into davidrg:master Aug 8, 2026
32 checks passed
@jgoerzen
jgoerzen deleted the jgoerzen/packet-size-bugfix branch August 8, 2026 01:35
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