-
Notifications
You must be signed in to change notification settings - Fork 804
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
Fix issue#1056 #1061 #1062
base: master
Are you sure you want to change the base?
Fix issue#1056 #1061 #1062
Conversation
Code Climate has analyzed commit bb785ec and detected 1 issue on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Can you consider doing some research to solve this issue too.
Try to find way to do it. |
@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. |
Okay that makes sense :)
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.
You're welcome, keep contributing... |
* check whether the file is a real pdf file or not (whether the file has the header of pdf file) | ||
*/ | ||
public static boolean isPdfFile(String filePath) { | ||
String header = getFileHeader(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will deal with it.
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
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.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
./gradlew assembleDebug assembleRelease
./gradlew checkstyle
Checklist: