Index: pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java	(revision 1331909)
+++ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java	(working copy)
@@ -446,10 +446,36 @@
             //Need to keep track of the
             out = stream.createFilteredStream( streamLength );
 
-            String endStream = null;
-            readUntilEndStream(out);
+            final int length;
+            if( streamLength instanceof COSNumber ) {
+                length = ((COSNumber)streamLength).intValue();
+            } else if( streamLength instanceof COSObject &&
+                       ((COSObject)streamLength).getObject() instanceof COSNumber ) {
+              length = ((COSNumber)((COSObject)streamLength).getObject()).intValue();
+            } else {
+              length = -1;
+            }
+
+            if (length == -1) {
+              // Couldn't determine length from dict: just
+              // scan until we find endstream:
+              readUntilEndStream(out);
+            } else {
+              // Copy length bytes over:
+              int left = length;
+              while( left > 0 ) {
+                final int chunk = Math.min( left, strmBuf.length );
+                final int readCount = pdfSource.read( strmBuf, 0, chunk );
+                if( readCount == -1 ) {
+                  break;
+                }
+                out.write( strmBuf, 0, readCount );
+                left -= readCount;
+              }
+            }
+
             skipSpaces();
-            endStream = readString();
+            String endStream = readString();
 
             if (!endStream.equals(ENDSTREAM_STRING))
             {
