FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix stream/zip leaks and infinite loop in export path by avinxshKD · Pull Request #1458 · processing/processing4 · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
33 changes: 19 additions & 14 deletions java/src/processing/mode/java/JavaBuild.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,9 @@ protected void addClasses(ZipOutputStream zos, File dir, String rootPath) throws
ZipEntry entry = new ZipEntry(relativePath);
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(sub));
PApplet.saveStream(zos, new FileInputStream(sub));
try (InputStream fis = new FileInputStream(sub)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand All @@ -1241,7 +1243,9 @@ protected void addDataFolder(ZipOutputStream zos) throws IOException {
ZipEntry entry = new ZipEntry(path.substring(offset));
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(dataFile));
PApplet.saveStream(zos, new FileInputStream(dataFile));
try (InputStream fis = new FileInputStream(dataFile)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand All @@ -1266,8 +1270,7 @@ protected void packClassPathIntoZipFile(String path,
// is it a jar file or directory?
if (piece.toLowerCase().endsWith(".jar") ||
piece.toLowerCase().endsWith(".zip")) {
try {
ZipFile file = new ZipFile(piece);
try (ZipFile file = new ZipFile(piece)) {
Enumeration<?> entries = file.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
Expand All @@ -1284,22 +1287,22 @@ protected void packClassPathIntoZipFile(String path,

zos.putNextEntry(entree);
byte[] buffer = new byte[(int) entry.getSize()];
InputStream is = file.getInputStream(entry);

int offset = 0;
int remaining = buffer.length;
while (remaining > 0) {
int count = is.read(buffer, offset, remaining);
offset += count;
remaining -= count;
try (InputStream is = file.getInputStream(entry)) {
int offset = 0;
int remaining = buffer.length;
while (remaining > 0) {
int count = is.read(buffer, offset, remaining);
if (count == -1) break;
offset += count;
remaining -= count;
}
}

zos.write(buffer);
zos.flush();
zos.closeEntry();
}
}
file.close();

} catch (IOException e) {
System.err.println("Error in file " + piece);
Expand Down Expand Up @@ -1348,7 +1351,9 @@ static protected void packClassPathIntoZipFileRecursive(File dir,
ZipEntry entry = new ZipEntry(nowfar);
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(sub));
PApplet.saveStream(zos, new FileInputStream(sub));
try (InputStream fis = new FileInputStream(sub)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand Down

Back | FazBrowse Home | New Git URL