pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1576202 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: encoding/Encoding.java pdfparser/BaseParser.java util/PDFStreamEngine.java util/PDFTextStripper.java util/ResourceLoader.java
Date Tue, 11 Mar 2014 07:01:32 GMT
Author: tilman
Date: Tue Mar 11 07:01:31 2014
New Revision: 1576202

URL: http://svn.apache.org/r1576202
Log:
PDFBOX-1946: catch SecurityException and resulting null values when run in an applet

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java?rev=1576202&r1=1576201&r2=1576202&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java Tue Mar 11
07:01:31 2014
@@ -70,15 +70,22 @@ public abstract class Encoding implement
         loadGlyphProperties("org/apache/pdfbox/resources/additional_glyphlist.properties");
 
         // Load an external glyph list file that user can give as JVM property
-        String location = System.getProperty("glyphlist_ext");
-        if (location != null)
+        try
         {
-            File external = new File(location);
-            if (external.exists())
+            String location = System.getProperty("glyphlist_ext");
+            if (location != null)
             {
-                loadGlyphProperties(location);
+                File external = new File(location);
+                if (external.exists())
+                {
+                    loadGlyphProperties(location);
+                }
             }
         }
+        catch (SecurityException e)  // can occur on Sytem.getProperty
+        {
+            // PDFBOX-1946 ignore and continue
+        }
 
         NAME_TO_CHARACTER.put(NOTDEF, "");
         NAME_TO_CHARACTER.put("fi", "fi");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1576202&r1=1576201&r2=1576202&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Tue Mar
11 07:01:31 2014
@@ -165,8 +165,19 @@ public abstract class BaseParser
     public BaseParser(InputStream input, boolean forceParsingValue)
             throws IOException
     {
+        int pushbacksize = 65536;
+        try
+        {
+            pushbacksize = Integer.getInteger(PROP_PUSHBACK_SIZE, 65536);
+        }
+        catch (SecurityException e) 
+        {
+            // PDFBOX-1946 getInteger calls System.getProperties, 
+            // which can get exception in an applet
+            // ignore and use default
+        }
         this.pdfSource = new PushBackInputStream(
-                new BufferedInputStream(input, 16384),  Integer.getInteger( PROP_PUSHBACK_SIZE,
65536 ) );
+                new BufferedInputStream(input, 16384), pushbacksize);
         this.forceParsing = forceParsingValue;
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1576202&r1=1576201&r2=1576202&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Tue Mar
11 07:01:31 2014
@@ -334,15 +334,18 @@ public class PDFStreamEngine
             glyphSpaceToTextSpaceFactor = 1f / fontMatrix.getValue(0, 0);
         }
         float spaceWidthText = 0;
-        try
-        {
-            // to avoid crash as described in PDFBOX-614
-            // lets see what the space displacement should be
-            spaceWidthText = (font.getSpaceWidth() * glyphSpaceToTextSpaceFactor);
-        }
-        catch (Throwable exception)
+        if (font != null) // PDFBOX-1946 font might still be null if in applet
         {
-            LOG.warn(exception, exception);
+            try
+            {
+                // to avoid crash as described in PDFBOX-614
+                // lets see what the space displacement should be
+                spaceWidthText = (font.getSpaceWidth() * glyphSpaceToTextSpaceFactor);
+            }
+            catch (Throwable exception)
+            {
+                LOG.warn(exception, exception);
+            }
         }
 
         if (spaceWidthText == 0)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java?rev=1576202&r1=1576201&r2=1576202&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java Tue Mar
11 07:01:31 2014
@@ -78,30 +78,39 @@ public class PDFTextStripper extends PDF
     //    pdftextstripper.drop
     static
     {
-        String prop = thisClassName+".indent";
-        String s = System.getProperty(prop);
-        if(s!=null && s.length()>0)
+        String sdrop = null, sindent = null;
+        try
+        {
+            String prop = thisClassName + ".indent";
+            sindent = System.getProperty(prop);
+            prop = thisClassName + ".drop";
+            sdrop = System.getProperty(prop);
+        }
+        catch (SecurityException e)
+        {
+            // PDFBOX-1946 when run in an applet
+            // ignore and use default
+        }
+        if (sindent != null && sindent.length() > 0)
         {
             try
             {
-                float f = Float.parseFloat(s);
+                float f = Float.parseFloat(sindent);
                 DEFAULT_INDENT_THRESHOLD = f;
             }
-            catch(NumberFormatException nfe)
+            catch (NumberFormatException nfe)
             {
-                        //ignore and use default
+                //ignore and use default
             }
         }
-        prop = thisClassName+".drop";
-        s = System.getProperty(prop);
-        if(s!=null && s.length()>0)
+        if (sdrop != null && sdrop.length() > 0)
         {
             try
             {
-                float f = Float.parseFloat(s);
+                float f = Float.parseFloat(sdrop);
                 DEFAULT_DROP_THRESHOLD = f;
             }
-            catch(NumberFormatException nfe)
+            catch (NumberFormatException nfe)
             {
                 //ignore and use default
             }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java?rev=1576202&r1=1576201&r2=1576202&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java Tue Mar 11
07:01:31 2014
@@ -51,8 +51,16 @@ public class ResourceLoader
      */
     public static InputStream loadResource( String resourceName ) throws IOException
     {
-        ClassLoader loader = ResourceLoader.class.getClassLoader();
-
+        ClassLoader loader = null;
+        try
+        {
+            loader = ResourceLoader.class.getClassLoader();
+        }
+        catch (SecurityException ex)
+        {
+            // ignore and try other alternatives
+        }
+   
         InputStream is = null;
 
         if( loader != null )
@@ -62,24 +70,31 @@ public class ResourceLoader
 
         //see sourceforge bug 863053, this is a fix for a user that
         //needed to have PDFBox loaded by the bootstrap classloader
-        if( is == null )
+        try
         {
-            loader = ClassLoader.getSystemClassLoader();
-            if( loader != null )
+            if( is == null )
             {
-                is = loader.getResourceAsStream( resourceName );
+                loader = ClassLoader.getSystemClassLoader();
+                if( loader != null )
+                {
+                    is = loader.getResourceAsStream( resourceName );
+                }
             }
-        }
 
-        if( is == null )
-        {
-            File f = new File( resourceName );
-            if( f.exists() )
+            if( is == null )
             {
-                is = new FileInputStream( f );
+                File f = new File( resourceName );
+                if( f.exists() )
+                {
+                    is = new FileInputStream( f );
+                }
             }
         }
-
+        catch (SecurityException ex)
+        {
+            // PDFBOX-1946 ignore and continue
+        }
+ 
         return is;
     }
 



Mime
View raw message