Images-to-PDF icon indicating copy to clipboard operation
Images-to-PDF copied to clipboard

Fix issue#1056 #1061

Open Jay-Ernest opened this issue 2 years ago • 5 comments

Description

Reason why leads to the crash

The testOOM.pdf is in a wrong pdf encoding format as it does not end with '%%EOF' which is the correct ending of any pdf file. As there is no '%%EOF', the program will not stop reading so that the memory will soon be used out, which leads to out of memory.

How I solve this problem

To solve this, I added some methods to check whether the file is in pdf format, with header(%PDF-(PDF version)) and end(%%EOF). I read the first 20 bytes to check the header in HEX and read backward from the last line to chech whether it is '%%EOF' in HEX. After doing so, the continuously crash was solved. I can normally open the feature PDF-TO-image without crashing.

Still some problems.

First is that, although the app doesn't crash because of OOM, the code still cannot get rid of the illegal pdf file, which means user can still choose the file. After clicking the transform bottom, the app will crash, but not continously crash. Second, my code cannot check the format like pdf ending with

%%EOF

that is a redundant enter.

Where I test the app

Using the virtual machine: Pixel 4 API 30 in Android Studio.

Fixes #1061 #1056

Type of change

Just put an x in the [] which are valid.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • [x] ./gradlew assembleDebug assembleRelease
  • [x] ./gradlew checkstyle

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings

Jay-Ernest avatar Apr 23 '22 16:04 Jay-Ernest

Code Climate has analyzed commit bb785ec2 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

codeclimate[bot] avatar Apr 23 '22 16:04 codeclimate[bot]

although the app doesn't crash because of OOM, the code still cannot get rid of the illegal pdf file

Can you consider doing some research to solve this issue too.

Second, my code cannot check the format like pdf ending with

Try to find way to do it.

codegsaini avatar Apr 23 '22 18:04 codegsaini

@Jay-Ernest Pull Request #1057 and #1062 (this) are more or less have similar commit, so please close either pull request and focus on one. And issue #1048 #1056 and #1061 are pointing out toward same problem, so please try to close those into single PR.

codegsaini avatar Apr 23 '22 18:04 codegsaini

@codegsaini I agree. And in my point of view, the two issue displays two bugs independently. That is, #1056 points out that we need to check the header but the end will not affect the result actually, while #1061 points out that if not check the end of PDF file(%%EOF) will lead to OutOfMemory. I will try to focus on it. I am doing my course project which is to fix some issues. As it is the first time to participate in Android development, it may be a little hard for me. Thank you for advice.

Jay-Ernest avatar Apr 24 '22 03:04 Jay-Ernest

And in my point of view, the two issue displays two bugs independently. That is, https://github.com/Swati4star/Images-to-PDF/issues/1056 points out that we need to check the header but the end will not affect the result actually, while https://github.com/Swati4star/Images-to-PDF/issues/1061 points out that if not check the end of PDF file(%%EOF) will lead to OutOfMemory.

Okay that makes sense :)

As it is the first time to participate in Android development, it may be a little hard for me.

Take your time, your goal should be learning things. Otherwise new issues and their fixes is a lifelong process. Involve yourself in finding the solution and you will learn a lot of things during the process.

Thank you for advice.

You're welcome, keep contributing...

codegsaini avatar Apr 24 '22 07:04 codegsaini