diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 6c0c16db0..8e402172f 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -133,6 +133,10 @@ var ChunkedStream = (function ChunkedStreamClosure() { return this.end - this.start; }, + get isEmpty() { + return this.length === 0; + }, + getByte: function ChunkedStream_getByte() { var pos = this.pos; if (pos >= this.end) { diff --git a/src/core/fonts.js b/src/core/fonts.js index 6d01710c7..5620cbcb3 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2204,7 +2204,13 @@ var Font = (function FontClosure() { this.defaultVMetrics = properties.defaultVMetrics; } - if (!file) { + if (!file || file.isEmpty) { + if (file) { + // Some bad PDF generators will include empty font files, + // attempting to recover by assuming that no file exists. + warn('Font file is empty in "' + name + '" (' + this.loadedName + ')'); + } + this.missingFile = true; // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. diff --git a/src/core/stream.js b/src/core/stream.js index a7d5d3456..f2996a66b 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -35,6 +35,9 @@ var Stream = (function StreamClosure() { get length() { return this.end - this.start; }, + get isEmpty() { + return this.length === 0; + }, getByte: function Stream_getByte() { if (this.pos >= this.end) { return -1; @@ -128,6 +131,12 @@ var DecodeStream = (function DecodeStreamClosure() { } DecodeStream.prototype = { + get isEmpty() { + while (!this.eof && this.bufferLength === 0) { + this.readBlock(); + } + return this.bufferLength === 0; + }, ensureBuffer: function DecodeStream_ensureBuffer(requested) { var buffer = this.buffer; var current; @@ -213,7 +222,7 @@ var DecodeStream = (function DecodeStreamClosure() { } return new Stream(this.buffer, start, length, dict); }, - skip: function Stream_skip(n) { + skip: function DecodeStream_skip(n) { if (!n) { n = 1; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index efd18259a..726a852d3 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -55,6 +55,7 @@ !gradientfill.pdf !bug903856.pdf !bug850854.pdf +!bug866395.pdf !basicapi.pdf !mixedfonts.pdf !shading_extend.pdf diff --git a/test/pdfs/bug866395.pdf b/test/pdfs/bug866395.pdf new file mode 100644 index 000000000..26af56bb9 Binary files /dev/null and b/test/pdfs/bug866395.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 0db9c348c..d7fd30bcc 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -682,6 +682,14 @@ "type": "eq", "about": "Seac with differences array that messes up mapping." }, + { "id": "bug866395", + "file": "pdfs/bug866395.pdf", + "md5": "f03bc77e84637241980b09a0a220f575", + "link": false, + "rounds": 1, + "type": "eq", + "about": "Font with an empty font file." + }, { "id": "ocs", "file": "pdfs/ocs.pdf", "md5": "2ade57e954ae7632749cf328daeaa7a8",