You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2021/01/20 18:56:00 UTC

[jira] [Resolved] (PDFBOX-5081) CFFParser.ByteSource.readRealNumber can better throw IOException

     [ https://issues.apache.org/jira/browse/PDFBOX-5081?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tilman Hausherr resolved PDFBOX-5081.
-------------------------------------
      Assignee: Tilman Hausherr
    Resolution: Fixed

Keeping the exception type as mentioned, but I added a message and a comment, thanks for the suggestion.

> CFFParser.ByteSource.readRealNumber can better throw IOException
> ----------------------------------------------------------------
>
>                 Key: PDFBOX-5081
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5081
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 1.8.16, 2.0.22
>            Reporter: Hao Zhong
>            Assignee: Tilman Hausherr
>            Priority: Major
>
> The code is as follows:
>  
> {code:java}
>  private static Double readRealNumber(CFFDataInput input, int b0) throws IOException
>     {
>         StringBuilder sb = new StringBuilder();
>         boolean done = false;
>         boolean exponentMissing = false;
>         boolean hasExponent = false;
>         while (!done)
>         {
>             int b = input.readUnsignedByte();
>             int[] nibbles = { b / 16, b % 16 };
>             for (int nibble : nibbles)
>             {
>                 switch (nibble)
>                 {
>                 case 0x0:
>                 ...
>  default:
>                     throw new IllegalArgumentException();
>                 }
>             }
>         }
>         if (exponentMissing)
>         {
>             // the exponent is missing, just append "0" to avoid an exception
>             // not sure if 0 is the correct value, but it seems to fit
>             // see PDFBOX-1522
>             sb.append("0");
>         }
>         if (sb.length() == 0)
>         {
>             return 0d;
>         }
>         try
>         {
>             return Double.valueOf(sb.toString());
>         }
>         catch (NumberFormatException ex)
>         {
>             throw new IOException(ex);
>         }
>     }
> {code}
> The while statement reads from input and checks nibble. If nibble is not as expected, the above code throws IllegalArgumentException. In similar situations, it is more reasonable to throw IOException. In addition, it is useful to debug, if the thrown exception contain the current nibble. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org