Uploaded image for project: 'XMLGraphicsCommons'
  1. XMLGraphicsCommons
  2. XGC-52

[PATCH] Crash of due to a NumberFormatException in XMPSchemaAdapter (problem of GMT parsing)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: None
    • Component/s: xmp
    • Labels:
    • Environment:
      Operating System: Linux
      Platform: PC

      Description

      Hi there !

      I think there is an issue in the method formatISO8601Date of the class org.apache.xmlgraphics.xmp.XMPSchemaAdapter

      When you have a negative GMT indication and when the negative number is less or equal to -10 then there is a problem.

      The piece of code:

      if (zoneOffsetHours > 0) {
      sb.append('+');
      } else {
      sb.append('-');
      }

      if (zoneOffsetHours < 10) {
      sb.append('0');
      }

      If I have zoneOffsetHours = -10 I will have zoneOffsetHours < 10 true (-10 < 10) so I will have sb concatenated with “-010” and not with “-10”.

      The result is : 2011-04-07T08:12:11-010:00

      I think we should have 2011-04-07T08:12:11-10:00 (no zero before the -10).

      It causes a NumberFormatException in my case, if I use FOP. the error is in the parseISO8601Date method of the same class :

      The line that crashes is the following :

      offset += Integer.parseInt(timeZonePart.substring(4, 6));

      The result of timeZonePart.substring(4, 6) is :0 and not 00 as it should be.

      Exception in thread "main" java.lang.NumberFormatException: For input string: ":0"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Integer.parseInt(Integer.java:449)
      at java.lang.Integer.parseInt(Integer.java:499)
      at org.apache.xmlgraphics.xmp.XMPSchemaAdapter.parseISO8601Date(XMPSchemaAdapter.java:236)
      at org.apache.xmlgraphics.xmp.XMPSchemaAdapter.getDateValue(XMPSchemaAdapter.java:282)
      at org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter.getMetadataDate(XMPBasicAdapter.java:170)
      at org.apache.fop.render.intermediate.IFRenderer.createDefaultDocumentMetadata(IFRenderer.java:549)
      at org.apache.fop.render.intermediate.IFRenderer.startPageSequence(IFRenderer.java:500)
      at org.apache.fop.area.RenderPagesModel.startPageSequence(RenderPagesModel.java:89)
      at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:98)
      at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:238)
      at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:120)
      at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:349)
      at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177)
      at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1102)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
      at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
      at com.micropol.micronix.engine.tools.pdf.PdfCreator.convertFO2PDF(PdfCreator.java:95)
      at com.micropol.micronix.engine.tools.pdf.PdfCreator.main(PdfCreator.java:121)

      As a result, each part of the word that has a GMT -10,-11,-12,-13 (Tonga) cannot use FOP 1.0. It is the case for many Pacific islands (I'm in French Polynesia).

      I think that the good test would be :

      if (Math.abs(zoneOffsetHours) < 10) {
      sb.append('0');
      }

        Attachments

        1. XMPSchemaAdapter.java
          17 kB
          Florian Barbera Vila Bollain

          Activity

            People

            • Assignee:
              general@xmlgraphics.apache.org XML Graphics Project Mailing List
              Reporter:
              f.barbera@hotmail.fr Florian Barbera Vila Bollain
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: