This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch mvnd-1.x
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
The following commit(s) were added to refs/heads/mvnd-1.x by this push:
new efbac1e7 Compare only the bytes read when verifying the extracted
native library (#1815)
efbac1e7 is described below
commit efbac1e76e49f19c886567c22e2eff90423b23c1
Author: Anders Gjendem <[email protected]>
AuthorDate: Mon Nov 23 20:08:13 2026 +0100
Compare only the bytes read when verifying the extracted native library
(#1815)
contentsEquals compared whole 8 KiB buffers, so a short last block also
compared stale bytes. With the JDK's Inflater on top of zlib-ng, the
system zlib on Fedora 40 and later, the stream for the jar entry writes
past the count it returns, and a correct file was reported as "Content
differs". jansi made the same fix in fusesource/jansi#318.
See #1262 and #1438.
---
.../org/mvndaemon/mvnd/nativ/MvndNativeLoader.java | 7 +--
.../mvndaemon/mvnd/nativ/MvndNativeLoaderTest.java | 50 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git
a/native/src/main/java/org/mvndaemon/mvnd/nativ/MvndNativeLoader.java
b/native/src/main/java/org/mvndaemon/mvnd/nativ/MvndNativeLoader.java
index cdfae9d0..fe2969cc 100644
--- a/native/src/main/java/org/mvndaemon/mvnd/nativ/MvndNativeLoader.java
+++ b/native/src/main/java/org/mvndaemon/mvnd/nativ/MvndNativeLoader.java
@@ -26,7 +26,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
-import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -135,8 +134,10 @@ public class MvndNativeLoader {
return "Read size different (" + numRead1 + " vs " +
numRead2 + ")";
}
// Otherwise same number of bytes read
- if (!Arrays.equals(buffer1, buffer2)) {
- return "Content differs";
+ for (int i = 0; i < numRead1; i++) {
+ if (buffer1[i] != buffer2[i]) {
+ return "Content differs";
+ }
}
// Otherwise same bytes read, so continue ...
} else {
diff --git
a/native/src/test/java/org/mvndaemon/mvnd/nativ/MvndNativeLoaderTest.java
b/native/src/test/java/org/mvndaemon/mvnd/nativ/MvndNativeLoaderTest.java
index eeccccab..21cef40b 100644
--- a/native/src/test/java/org/mvndaemon/mvnd/nativ/MvndNativeLoaderTest.java
+++ b/native/src/test/java/org/mvndaemon/mvnd/nativ/MvndNativeLoaderTest.java
@@ -18,12 +18,62 @@
*/
package org.mvndaemon.mvnd.nativ;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.Random;
+
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
public class MvndNativeLoaderTest {
+ // contentsEquals reads in blocks of this size
+ private static final int BLOCK_SIZE = 8192;
+
@Test
public void testLoadJansi() {
MvndNativeLoader.initialize();
}
+
+ @Test
+ public void contentsEqualsIgnoresBytesPastWhatWasRead() throws Exception {
+ byte[] data = randomBytes(BLOCK_SIZE + 192);
+ // Seen on Fedora, where the JDK's Inflater links the system zlib
(zlib-ng):
+ // reading a jar entry changed buffer bytes past the count read()
returned.
+ InputStream scribbling = new ByteArrayInputStream(data) {
+ @Override
+ public synchronized int read(byte[] b, int off, int len) {
+ int n = super.read(b, off, len);
+ if (n > 0 && n < len) {
+ b[off + n] ^= 0x55;
+ }
+ return n;
+ }
+ };
+ assertNull(contentsEquals(scribbling, new ByteArrayInputStream(data)));
+ }
+
+ @Test
+ public void contentsEqualsReportsDifferentBytes() throws Exception {
+ byte[] data = randomBytes(BLOCK_SIZE + 192);
+ byte[] other = data.clone();
+ other[BLOCK_SIZE + 100] ^= 0x55;
+ assertEquals(
+ "Content differs", contentsEquals(new
ByteArrayInputStream(data), new ByteArrayInputStream(other)));
+ }
+
+ private static String contentsEquals(InputStream in1, InputStream in2)
throws Exception {
+ Method m = MvndNativeLoader.class.getDeclaredMethod("contentsEquals",
InputStream.class, InputStream.class);
+ m.setAccessible(true);
+ return (String) m.invoke(null, in1, in2);
+ }
+
+ private static byte[] randomBytes(int size) {
+ byte[] data = new byte[size];
+ new Random(1).nextBytes(data);
+ return data;
+ }
}