Skip to content

Fix Unix socket paths and array bounds in the JNI code - #97

Merged
eed3si9n merged 2 commits into
sbt:developfrom
lrytz:pr/jni-unix-path-length
Oct 29, 2026
Merged

eed3si9n merged 2 commits into
sbt:developfrom
lrytz:pr/jni-unix-path-length

Conversation

@lrytz

@lrytz lrytz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Two memory safety bugs in the JNI code for Unix sockets:

  • A socket path longer than the system's limit overwrote memory and crashed the JVM. It now fails with an IOException, as with JNA.
  • write(b, off, len) with off and len outside the array sent the memory after the array over the socket. The streams now check the bounds.

The commit messages have the details.

lrytz and others added 2 commits October 28, 2026 11:00
Unix socket paths have a size limit: 104 bytes on macOS, 108 on Linux.
The JNI code copied the path into a fixed-size buffer without checking
its length, so a longer path overwrote memory and crashed the JVM. Such
paths are realistic, for example under ~/.sbt in a deep home directory.

Now bind and connect throw an IOException for a path that is too long,
as the JNA code already did.

Two related bugs in connect are fixed too: it passed the number of
characters in the path instead of the number of bytes, so paths with
non-ASCII characters failed, and it leaked the socket when it failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write(b, off, len) didn't check that off and len are within the array.
With JNI, the native code then read past the end of the array and sent
whatever memory came after it over the socket. read(b, off, len) only
noticed bad bounds after it had already consumed the data.

Now both throw IndexOutOfBoundsException before doing anything, as
InputStream and OutputStream require.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lrytz lrytz mentioned this pull request Oct 28, 2026

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@eed3si9n
eed3si9n merged commit b2c05d3 into sbt:develop Oct 29, 2026
7 checks passed
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