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

BufferedInputStream: Allow jumping backwards to an already processed position #2344

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

jpstotz
Copy link
Collaborator

@jpstotz jpstotz commented Nov 15, 2024

Some APK resources.arsc seem to use disordered entries, which collides with our approach to read them sequentially from the InputStream.

As a workaround this PR introduces a BufferedInputStream and mark/reset support for ParserStream which allows us to jump back (up to 32k) in stream to read the disordered type chunk entries.

fixes #2343

Copy link
Owner

@skylot skylot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍
But seems that in most cases input in ParserStream already a BufferedInputStream, so we're just increasing its buffer size.
Anyway, it is fine as a workaround, but we will need to migrate to byte array anyway because this way it is closer to Android code with jumps to offsets. This shouldn't be hard, we just need to change ParserStream implementation.

@skylot skylot merged commit fe9d3bc into skylot:master Nov 15, 2024
4 checks passed
@jpstotz
Copy link
Collaborator Author

jpstotz commented Nov 15, 2024

@skylot I checked the usages and in most cases the InputStream came directly from ZIP file. Only one case used BufferedInputStream (which I removed in this PR).

I see. resources.arsc is stored without compression in the ZIP file. So Android directly maps the ZIP file data to memory and operates on it.

@jpstotz jpstotz deleted the bufferedResParse branch November 15, 2024 15:13
@skylot
Copy link
Owner

skylot commented Nov 15, 2024

in most cases the InputStream came directly from ZIP file

Everything should be from here:

public static InputStream getInputStreamForEntry(ZipFile zipFile, ZipEntry entry) throws IOException {
if (DISABLE_CHECKS) {
return new BufferedInputStream(zipFile.getInputStream(entry));
}
InputStream in = zipFile.getInputStream(entry);
LimitedInputStream limited = new LimitedInputStream(in, entry.getSize());
return new BufferedInputStream(limited);
}

otherwise it is not secured/checked and should be fixed.

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

Successfully merging this pull request may close these issues.

Jadx can not parse resource type chunks with unordered entries
2 participants