Skip to content

Commit 300aa78

Browse files
gnodetclaude
andauthored
Fix native library loading failure caused by incorrect buffer comparison (#317) (#318)
Compare only the bytes actually read from each stream instead of the entire 8192-byte buffer in contentsEquals(). When the final chunk is smaller than the buffer, stale bytes from the previous iteration could cause a false mismatch, preventing the native library from loading. Uses a byte-by-byte loop instead of Arrays.equals() to maintain JDK 8 compatibility. Fixes #317 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c20d88f commit 300aa78

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/main/java/org/fusesource/jansi/internal/JansiLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.net.URL;
4141
import java.nio.file.Files;
4242
import java.nio.file.StandardCopyOption;
43-
import java.util.Arrays;
4443
import java.util.LinkedList;
4544
import java.util.List;
4645
import java.util.Properties;
@@ -158,8 +157,10 @@ private static String contentsEquals(InputStream in1, InputStream in2) throws IO
158157
return "Read size different (" + numRead1 + " vs " + numRead2 + ")";
159158
}
160159
// Otherwise same number of bytes read
161-
if (!Arrays.equals(buffer1, buffer2)) {
162-
return "Content differs";
160+
for (int i = 0; i < numRead1; i++) {
161+
if (buffer1[i] != buffer2[i]) {
162+
return "Content differs";
163+
}
163164
}
164165
// Otherwise same bytes read, so continue ...
165166
} else {

0 commit comments

Comments
 (0)