pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tboe...@apache.org
Subject svn commit: r1702917 - /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
Date Mon, 14 Sep 2015 12:23:49 GMT
Author: tboehme
Date: Mon Sep 14 12:23:49 2015
New Revision: 1702917

URL: http://svn.apache.org/r1702917
Log:
PDFBOX-2941: prevent parallel access to stream in StreamPane (e.g. creating image+hex data);
fixes random crashes typically in RandomAccess.readRemainingBytes

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java?rev=1702917&r1=1702916&r2=1702917&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
Mon Sep 14 12:23:49 2015
@@ -196,7 +196,11 @@ public class StreamPane implements Actio
     {
         if (stream.isImage())
         {
-            BufferedImage image = stream.getImage(resources);
+            BufferedImage image;
+            synchronized (stream)
+            {
+                image = stream.getImage(resources);
+            }
             view.showStreamImage(image);
 
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -211,7 +215,10 @@ public class StreamPane implements Actio
     private void requestStreamText(String command) throws IOException
     {
         new DocumentCreator(command).execute();
-        hexView.changeData(IOUtils.toByteArray(stream.getStream(command)));
+        synchronized (stream)
+        {
+            hexView.changeData(IOUtils.toByteArray(stream.getStream(command)));
+        }
     }
 
     /**
@@ -231,17 +238,20 @@ public class StreamPane implements Actio
         @Override
         protected StyledDocument doInBackground()
         {
-            InputStream inputStream = stream.getStream(filterKey);
-            if (isContentStream && Stream.UNFILTERED.equals(filterKey))
+            synchronized (stream)
             {
-                StyledDocument document = getContentStreamDocument(inputStream);
-                if (document != null)
+                InputStream inputStream = stream.getStream(filterKey);
+                if (isContentStream && Stream.UNFILTERED.equals(filterKey))
                 {
-                    return document;
+                    StyledDocument document = getContentStreamDocument(inputStream);
+                    if (document != null)
+                    {
+                        return document;
+                    }
+                    return getDocument(stream.getStream(filterKey));
                 }
-                return getDocument(stream.getStream(filterKey));
+                return getDocument(inputStream);
             }
-            return getDocument(inputStream);
         }
 
         @Override
@@ -290,15 +300,18 @@ public class StreamPane implements Actio
 
         private StyledDocument getDocument(InputStream inputStream)
         {
-            String data = getStringOfStream(inputStream);
             StyledDocument docu = new DefaultStyledDocument();
-            try
-            {
-                docu.insertString(0, data, null);
-            }
-            catch (BadLocationException e)
+            if (inputStream != null)
             {
-                e.printStackTrace();
+                String data = getStringOfStream(inputStream);
+                try
+                {
+                    docu.insertString(0, data, null);
+                }
+                catch (BadLocationException e)
+                {
+                    e.printStackTrace();
+                }
             }
             return docu;
         }



Mime
View raw message