Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of fonts with empty font files (bug 866395 and issue 3522) #4809

Merged
merged 2 commits into from
May 19, 2014
Merged

Fix loading of fonts with empty font files (bug 866395 and issue 3522) #4809

merged 2 commits into from
May 19, 2014

Conversation

Snuffleupagus
Copy link
Collaborator

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=866395.
Fixes #3522.

I've struggled with the best way to create the isEmpty property for the DecodeStream. The first idea, to check if peekBytes(1) returns data won't work at the end of the stream. Furthermore just checking if this.buffer is null or empty won't work either, because if ensureBuffer has been called that no longer holds even if the stream was actually empty. The only remaining (simple) approach seem to be to read enough of the stream and then check if this.bufferLength === 0, since that should only happen when the stream is actually empty.

If the current approach used in this PR isn't any good, we might instead do something along these lines:

get isEmpty() {
  if (this.pos === 0) {
    return (this.peekBytes(1).length === 0);
  }
  var currentPos = this.pos;
  this.reset();
  var firstByte = this.peekBytes(1);
  this.skip(currentPos);
  return (firstByte.length === 0);
}

@yurydelendik Which solution do you prefer?

@@ -2204,7 +2204,13 @@ var Font = (function FontClosure() {
this.defaultVMetrics = properties.defaultVMetrics;
}

if (!file) {
if (!file || file.isEmpty) {
if (!!file) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if (file) { will look as good

@yurydelendik
Copy link
Contributor

I think it looks good now. Could you add one isEmpty to the https://github.com/mozilla/pdf.js/blob/master/src/core/chunked_stream.js ?

@Snuffleupagus
Copy link
Collaborator Author

Done, done and done; thanks for the very quick review!

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.22.172.223:8877/dd69a61069a4f0f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/7481e1ac1fcc1a1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/dd69a61069a4f0f/output.txt

Total script time: 2.81 mins

  • Font tests: FAILED
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://107.22.172.223:8877/dd69a61069a4f0f/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/7481e1ac1fcc1a1/output.txt

Total script time: 25.99 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik
Copy link
Contributor

/botio-windows test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/1c67e0381b4251e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/1c67e0381b4251e/output.txt

Total script time: 23.60 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_makeref from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/da6ef04bf008ec7/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/c7974e8012af51c/output.txt

@yurydelendik
Copy link
Contributor

Thank you for the patch

yurydelendik added a commit that referenced this pull request May 19, 2014
Fix loading of fonts with empty font files (bug 866395 and issue 3522)
@yurydelendik yurydelendik merged commit 5cd6483 into mozilla:master May 19, 2014
@Snuffleupagus Snuffleupagus deleted the bug-866395-redux branch May 19, 2014 16:31
@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/c7974e8012af51c/output.txt

Total script time: 23.87 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/da6ef04bf008ec7/output.txt

Total script time: 26.25 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Labels in the figures not displayed properly
3 participants