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

Attempt to recover valid format 3 FDSelect data from broken CFF fonts (bug 1146106) #7361

Merged
merged 1 commit into from
Jun 7, 2016
Merged

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented May 26, 2016

According to the CFF specification, see http://partners.adobe.com/public/developer/en/font/5176.CFF.pdf#G3.46884, for format 3 FDSelect data: "The first range must have a ‘first’ GID of 0".
Since the PDF file (attached in the bug) violates that part of the specification, this patch tries to recover valid FDSelect data to prevent OTS from rejecting the font.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1146106.

r? @brendandahl

Edit: Compared to the first version of this patch, the latest version contains a number of improvements, hence I'm updating it from f? to r?.
Please also note that this patch, as far as I know, fixes the only currently remaining font regression.

@Snuffleupagus
Copy link
Collaborator Author

/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/23fcd2249cbb6ae/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/1d6f8a46b60ce37/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/23fcd2249cbb6ae/output.txt

Total script time: 20.91 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/1d6f8a46b60ce37/output.txt

Total script time: 27.66 mins

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

break;
case 3:
var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
for (i = 0; i < rangesCount; ++i) {
var first = (bytes[pos++] << 8) | bytes[pos++];
if (i === 0 && first !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to just set the invalid flag and first = 0 here, then just fix up the rawbytes below instead of re-calling parseFDSelect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, we can do that. It's actually what I did in the initial patch, but then I got a bit paranoid that if we encounter sufficiently weird FDSelect data, that it could unnecessarily breaking things :-)
E.g. what happens if the first range is wrong, but the rest of the FDSelect data is weird enough that the total length becomes correct anyway?

However, given that I've not seen that happen, it probably just a theoretical concern. So, if you want me to, I'll remove the recoveryMode and just do the adjustment directly!

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do the simpler approach for now so it's easier to follow. Hopefully we won't have to touch this code again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Works for me; I've pushed an updated patch.

…ts (bug 1146106)

According to the CFF specification, see http://partners.adobe.com/public/developer/en/font/5176.CFF.pdf#G3.46884, for `format 3` FDSelect data: "The first range must have a ‘first’ GID of 0".
Since the PDF file (attached in the bug) violates that part of the specification, this patch tries to recover valid FDSelect data to prevent OTS from rejecting the font.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1146106.
@brendandahl
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jun 6, 2016

From: Bot.io (Windows)


Received

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

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

@pdfjsbot
Copy link

pdfjsbot commented Jun 6, 2016

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/6942ead328e25b8/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 6, 2016

From: Bot.io (Windows)


Success

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

Total script time: 21.28 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Jun 6, 2016

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/6942ead328e25b8/output.txt

Total script time: 27.45 mins

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

@brendandahl
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

pdfjsbot commented Jun 7, 2016

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/3cf83f276c26687/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 7, 2016

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/38fad8f1b757dc2/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 7, 2016

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/3cf83f276c26687/output.txt

Total script time: 21.24 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Jun 7, 2016

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/38fad8f1b757dc2/output.txt

Total script time: 26.06 mins

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

@brendandahl brendandahl merged commit c4db4dd into mozilla:master Jun 7, 2016
@brendandahl
Copy link
Contributor

Thanks!

@Snuffleupagus Snuffleupagus deleted the bug-1146106 branch June 7, 2016 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants