Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipFile doesn't chunk entries correctly #954

Open
Chocohead opened this issue Sep 21, 2024 · 0 comments
Open

ZipFile doesn't chunk entries correctly #954

Chocohead opened this issue Sep 21, 2024 · 0 comments

Comments

@Chocohead
Copy link

Noticed this when trying to read zip entries by their declared size:

try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("test.zip"))) {
	zip.putNextEntry(new ZipEntry("example"));
	byte[] in = new byte[3000]; //Just something bigger than the 2048 buffer TInputStream uses
	Arrays.fill(in, (byte) 1);
	zip.write(in);
}

try (ZipFile zip = new ZipFile("test.zip")) {
	ZipEntry entry = zip.getEntry("example");
	byte[] read;
	try (InputStream in = zip.getInputStream(entry)) {
		read = stream.readNBytes((int) entry.getSize());
	}
	assert read.length == 3000;
}

When run as JavaScript at least, I get the following crash....

Exception in thread "main" java.io.EOFException
	at org.teavm.classlib.java.util.zip.TInflaterInputStream.read(TInflaterInputStream.java:106)
	at org.teavm.classlib.java.util.zip.TZipFile$ZipInflaterInputStream.read(TZipFile.java:331)
	at org.teavm.classlib.java.io.TInputStream.readNBytes(TInputStream.java:108)
	at com.chocohead.Example.main(Example.java:46)

Interestingly enough, using a ZipInputStream works fine:

try (ZipInputStream zip = new ZipInputStream(new FileInputStream("test.zip"))) {
	zip.getNextEntry();
	byte[] read = zip.readNBytes(3000);
	assert read.length == 3000;
}
konsoletyper added a commit that referenced this issue Oct 22, 2024
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

No branches or pull requests

1 participant