Possible fix for Oracle's Bug JDK-8314112#175
Possible fix for Oracle's Bug JDK-8314112#175viktor-merkel wants to merge 5 commits intoapache:2.0from
Conversation
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/tags/2.0.30@1913484 13f79535-47bb-0310-9956-ffa450edef68
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/tags/2.0.30@1913493 13f79535-47bb-0310-9956-ffa450edef68
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/tags/2.0.30@1913512 13f79535-47bb-0310-9956-ffa450edef68
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/tags/2.0.30@1913518 13f79535-47bb-0310-9956-ffa450edef68
|
I'm wondering whether calls like I'm also wondering whether these stunts are needed. Same for |
|
I'm also wondering whether it wouldn't be easier (and faster on runtime) to just catch the NegativeArraySizeException in PageDrawer at the three places you indicated, until java fixes that bug. (despite all the work you put into that fix, sorry) |
Yes, on Java 16+ |
|
I agree with @THausherr the proposed patch is kind of hacky and it just solves a corner case. I'd prefer the alternative solution, catching the exception and waiting for a java fix |
…#175 git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/3.0@1915121 13f79535-47bb-0310-9956-ffa450edef68
…#175 git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/2.0@1915122 13f79535-47bb-0310-9956-ffa450edef68
|
@THausherr Thanks for taking a look at my pull request. The problem with the simple "catch exceptions" solution is that it does not prevent the program from attempting to create a very large data buffer due to the division by zero, and this leads to an OutOfMemoryError of the entire application: Caused by: java.lang.OutOfMemoryError: Java heap space |
|
Yeah I should have tested your program. I reverted the whole thing for a different reason, the exception doesn't happen at the place where I catch it. So you're right, the method shouldn't be called at all, i.e. the call should be prevented. Please try to adjust your code so that it doesn't do any of the "forbidden" calls, and without jdk code. |
This PR fixes the NegativeArraySizeException during print when scaling causes width and height to be 0, which can lead to application freeze unexpectedly.
The sun.awt.windows.WPathGraphics class in Java contains a code segment within the drawImageToPlatform function that can lead to a NegativeArraySizeException under specific conditions. This issue arises when the scaling values in AffineTransform are set in a way that causes w and h (width and height) to have a value of 0.
"Proposed Solution:
To prevent the occurrence of the NegativeArraySizeException, a check should be introduced in the code to ensure that w and h are not 0 before proceeding with the calculation of minDpi. If either w or h is found to be 0, an appropriate error handling mechanism should be implemented to avoid division by zero."
Oracle bug submission:
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8314112
This PR provides a fix for PDFBox that checks for a correct scale before forwarding the application flow to the problematic part of the JRE.