You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Jose Novacho (Jira)" <ji...@apache.org> on 2020/01/17 09:25:00 UTC

[jira] [Updated] (PDFBOX-4742) Incorrect handling of float Infinity and NaN

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

Jose Novacho updated PDFBOX-4742:
---------------------------------
    Description: 
When creating document, there is an issue if the operand for a command is floating number positive or negative Infinity, or NaN.

The problem is in method {{{color:#172b4d} org.apache.pdfbox.pdmodel.PDPageContentStream#write. {color}}} In case the method {{org.apache.pdfbox.pdmodel.PDPageContentStream#writeOperand(float)}} receives as operand a floating number with value {{Float.POSITIVE_INFINITY}} or {{Float.NEGATIVE_INFINITY}} the result of formating is symbol for infinity: ∞ (unicode 0x221E). The NaN produce unicode symbol 0xFFFD (replacement character). This is then later converted to bytes using the US_ASCII encoding which produces symbol *?* (0x3F) this symbol is then put into the content stream and the resulting PDF is invalid.

 

Mimimal working example to reproduce this issue.

 
{code:java}
// code placeholder
public class InfiniteError {
    public static void main(String[] args) throws IOException {
        PDDocument document = new PDDocument();
        PDPage page = new PDPage();
        document.addPage(page);        PDFont font = PDType1Font.HELVETICA_BOLD;        PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.OVERWRITE, false);        contentStream.beginText();
        contentStream.setFont(font, 12);
        contentStream.newLineAtOffset(100, Float.POSITIVE_INFINITY);
        contentStream.showText("Hello World");
        contentStream.endText();        contentStream.close();        document.save("Hello World.pdf");
        document.close();    }
}
{code}
 

  was:
When creating document, there is an issue if the operand for a command is floating number positive or negative Infinity, or NaN.

The problem is in method {{{color:#172b4d} org.apache.pdfbox.pdmodel.PDPageContentStream#write. {color}}} In case the method {{org.apache.pdfbox.pdmodel.PDPageContentStream#writeOperand(float)}} receives as operand a floating number with value Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY the result of formating is symbol for infinity: ∞ (unicode 0x221E). The NaN produce unicode symbol 0xFFFD (replacement character). This is then later converted to bytes using the US_ASCII encoding which produces symbol *?* (0x3F) this symbol is then put into the content stream and the resulting PDF is invalid.

 

Mimimal working example to reproduce this issue.

 
{code:java}
// code placeholder
public class InfiniteError {
    public static void main(String[] args) throws IOException {
        PDDocument document = new PDDocument();
        PDPage page = new PDPage();
        document.addPage(page);        PDFont font = PDType1Font.HELVETICA_BOLD;        PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.OVERWRITE, false);        contentStream.beginText();
        contentStream.setFont(font, 12);
        contentStream.newLineAtOffset(100, Float.POSITIVE_INFINITY);
        contentStream.showText("Hello World");
        contentStream.endText();        contentStream.close();        document.save("Hello World.pdf");
        document.close();    }
}
{code}
 


> Incorrect handling of float Infinity and NaN
> --------------------------------------------
>
>                 Key: PDFBOX-4742
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4742
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel, Writing
>    Affects Versions: 2.0.8, 2.0.18
>            Reporter: Jose Novacho
>            Priority: Major
>         Attachments: Hello World.pdf
>
>
> When creating document, there is an issue if the operand for a command is floating number positive or negative Infinity, or NaN.
> The problem is in method {{{color:#172b4d} org.apache.pdfbox.pdmodel.PDPageContentStream#write. {color}}} In case the method {{org.apache.pdfbox.pdmodel.PDPageContentStream#writeOperand(float)}} receives as operand a floating number with value {{Float.POSITIVE_INFINITY}} or {{Float.NEGATIVE_INFINITY}} the result of formating is symbol for infinity: ∞ (unicode 0x221E). The NaN produce unicode symbol 0xFFFD (replacement character). This is then later converted to bytes using the US_ASCII encoding which produces symbol *?* (0x3F) this symbol is then put into the content stream and the resulting PDF is invalid.
>  
> Mimimal working example to reproduce this issue.
>  
> {code:java}
> // code placeholder
> public class InfiniteError {
>     public static void main(String[] args) throws IOException {
>         PDDocument document = new PDDocument();
>         PDPage page = new PDPage();
>         document.addPage(page);        PDFont font = PDType1Font.HELVETICA_BOLD;        PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.OVERWRITE, false);        contentStream.beginText();
>         contentStream.setFont(font, 12);
>         contentStream.newLineAtOffset(100, Float.POSITIVE_INFINITY);
>         contentStream.showText("Hello World");
>         contentStream.endText();        contentStream.close();        document.save("Hello World.pdf");
>         document.close();    }
> }
> {code}
>  



--
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