From 3880b2309a1a442b13d5d3b9dcebae141d868627 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 27 Jun 2025 23:25:45 +0000 Subject: [PATCH 1/4] fix --- test/jdk/build/AbsPathsInImage.java | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index 1aa7e59941e8e..82592ceb61918 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -180,7 +180,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } private void scanFile(Path file, List searchPatterns) throws IOException { - List matches = scanBytes(Files.readAllBytes(file), searchPatterns); + int bytesRead; + byte[] buffer = new byte[8192]; + List matches = new ArrayList<>(); + try(InputStream inputStream = Files.newInputStream(file)) { + while((bytesRead = inputStream.read(buffer)) != -1) { + matches.addAll(scanBytes(buffer, bytesRead, searchPatterns)); + } + } if (matches.size() > 0) { matchFound = true; System.out.println(file + ":"); @@ -192,10 +199,15 @@ private void scanFile(Path file, List searchPatterns) throws IOException } private void scanZipFile(Path zipFile, List searchPatterns) throws IOException { + ZipEntry zipEntry; + int bytesRead; + byte[] buffer = new byte[8192]; try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))) { - ZipEntry zipEntry; while ((zipEntry = zipInputStream.getNextEntry()) != null) { - List matches = scanBytes(zipInputStream.readAllBytes(), searchPatterns); + List matches = new ArrayList<>(); + while((bytesRead = zipInputStream.read(buffer)) != -1) { + matches.addAll(scanBytes(buffer, bytesRead, searchPatterns)); + } if (matches.size() > 0) { matchFound = true; System.out.println(zipFile + ", " + zipEntry.getName() + ":"); @@ -208,19 +220,19 @@ private void scanZipFile(Path zipFile, List searchPatterns) throws IOExc } } - private List scanBytes(byte[] data, List searchPatterns) { + private List scanBytes(byte[] data, int dataLength, List searchPatterns) { List matches = new ArrayList<>(); - for (int i = 0; i < data.length; i++) { + for (int i = 0; i < dataLength; i++) { for (byte[] searchPattern : searchPatterns) { boolean found = true; for (int j = 0; j < searchPattern.length; j++) { - if ((i + j >= data.length || data[i + j] != searchPattern[j])) { + if ((i + j >= dataLength || data[i + j] != searchPattern[j])) { found = false; break; } } if (found) { - matches.add(new String(data, charsStart(data, i), charsOffset(data, i, searchPattern.length))); + matches.add(new String(data, charsStart(data, i), charsOffset(data, dataLength, i, searchPattern.length))); // No need to search the same string for multiple patterns break; } @@ -240,9 +252,9 @@ private int charsStart(byte[] data, int startIndex) { return index + 1; } - private int charsOffset(byte[] data, int startIndex, int startOffset) { + private int charsOffset(byte[] data, int dataLength, int startIndex, int startOffset) { int offset = startOffset; - while (startIndex + ++offset < data.length) { + while (startIndex + ++offset < dataLength) { byte datum = data[startIndex + offset]; if (datum < 32 || datum > 126) { break; From 396f36c401c4e10706c011402c8bac7a8fc03190 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 27 Jun 2025 23:33:59 +0000 Subject: [PATCH 2/4] remove trailing whitespace --- test/jdk/build/AbsPathsInImage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index 82592ceb61918..43595d7dd7795 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -207,7 +207,7 @@ private void scanZipFile(Path zipFile, List searchPatterns) throws IOExc List matches = new ArrayList<>(); while((bytesRead = zipInputStream.read(buffer)) != -1) { matches.addAll(scanBytes(buffer, bytesRead, searchPatterns)); - } + } if (matches.size() > 0) { matchFound = true; System.out.println(zipFile + ", " + zipEntry.getName() + ":"); From 5d880ecb403be4a4667ba10edb7542a8dd02f01c Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 27 Jun 2025 23:45:39 +0000 Subject: [PATCH 3/4] remove 8341024 --- test/jdk/build/AbsPathsInImage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index 43595d7dd7795..b1c986184cbc4 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -42,7 +42,7 @@ * @requires !vm.debug * @comment ASAN keeps the 'unwanted' paths in the binaries because of its build options * @requires !vm.asan - * @run main/othervm -Xmx900m AbsPathsInImage + * @run main AbsPathsInImage */ public class AbsPathsInImage { From eb63b16238ae24f0a47a3ee356be94a341c3c0fe Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Tue, 8 Jul 2025 20:52:11 +0000 Subject: [PATCH 4/4] style improvements --- test/jdk/build/AbsPathsInImage.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index b1c986184cbc4..54170d780ec10 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -51,6 +51,7 @@ public class AbsPathsInImage { public static final String DIR_PROPERTY = "jdk.test.build.AbsPathsInImage.dir"; private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("windows"); private static final boolean IS_LINUX = System.getProperty("os.name").toLowerCase().contains("linux"); + private static final int DEFAULT_BUFFER_SIZE = 8192; private boolean matchFound = false; @@ -181,10 +182,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO private void scanFile(Path file, List searchPatterns) throws IOException { int bytesRead; - byte[] buffer = new byte[8192]; + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; List matches = new ArrayList<>(); - try(InputStream inputStream = Files.newInputStream(file)) { - while((bytesRead = inputStream.read(buffer)) != -1) { + try (InputStream inputStream = Files.newInputStream(file)) { + while ((bytesRead = inputStream.read(buffer)) != -1) { matches.addAll(scanBytes(buffer, bytesRead, searchPatterns)); } } @@ -201,11 +202,11 @@ private void scanFile(Path file, List searchPatterns) throws IOException private void scanZipFile(Path zipFile, List searchPatterns) throws IOException { ZipEntry zipEntry; int bytesRead; - byte[] buffer = new byte[8192]; + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))) { while ((zipEntry = zipInputStream.getNextEntry()) != null) { List matches = new ArrayList<>(); - while((bytesRead = zipInputStream.read(buffer)) != -1) { + while ((bytesRead = zipInputStream.read(buffer)) != -1) { matches.addAll(scanBytes(buffer, bytesRead, searchPatterns)); } if (matches.size() > 0) {