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

Wrong file is produced when align is not needed #11

Closed
cr4zyserb opened this issue May 16, 2024 · 3 comments
Closed

Wrong file is produced when align is not needed #11

cr4zyserb opened this issue May 16, 2024 · 3 comments

Comments

@cr4zyserb
Copy link

cr4zyserb commented May 16, 2024

Error is in the code here:

        file.seek(0);
        if (neededAlignments.size() == 0) {
            // there is no needed alignment, stream it all!
            byte[] buffer = new byte[8192];
            while (file.read(buffer) != -1) out.write(buffer);
            return;
        }

should be:

        file.seek(0);
        if (neededAlignments.size() == 0) {
            // there is no needed alignment, stream it all!
            byte[] buffer = new byte[8192];
            int len;
            while (-1 != (len = file.read(buffer))){
                out.write(buffer, 0, len);
            }
            return;
        }

Original code would write extra data at the end in the most cases, except when file_size % 8192 == 0, which would cause apksigner to fail with Malformed APK: not a ZIP archive

@iyxan23
Copy link
Owner

iyxan23 commented May 16, 2024

Thanks for the catch! I wasn't very familiar with Java streams at the time so that was a mistake on my part 😅

Would you be kind enough to make a PR instead? So that'd count as a contribution. Thanks!

@cr4zyserb
Copy link
Author

You're welcome. I think it is easier if you fix it directly in the code. If you prefer that I do PR, I can do it, but it is such a minor fix that it is not even worth considering it as a contribution 😃

@iyxan23
Copy link
Owner

iyxan23 commented May 17, 2024

Sure, if you said so! Thanks for the fix

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

2 participants