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

Prevent issues, in PDFDocument.fieldObjects, for invalid Annotations #12516

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

For an invalid Annotation, there's one code-path where undefined is returned from AnnotationFactory._create. That'd currently, incorrectly, trigger an error during the PDFDocument._collectFieldObjects parsing which thus seem good to avoid.
Along these lines, the filtering in PDFDocument.fieldObjects is also updated to handle both null and undefined the same way.

For an invalid Annotation, there's one code-path where `undefined` is returned from `AnnotationFactory._create`. That'd currently, incorrectly, trigger an error during the `PDFDocument._collectFieldObjects` parsing which thus seem good to avoid.
Along these lines, the filtering in `PDFDocument.fieldObjects` is also updated to handle both `null` and `undefined` the same way.
@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/71a50e868e9f893/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/71a50e868e9f893/output.txt

Total script time: 4.35 mins

  • Unit Tests: FAILED

@calixteman
Copy link
Contributor

Good catch.

@timvandermeij
Copy link
Contributor

timvandermeij commented Oct 22, 2020

Are you sure this can actually happen? undefined is returned at https://github.com/mozilla/pdf.js/blob/master/src/core/annotation.js#L81, which can only happen if the ref in https://github.com/mozilla/pdf.js/blob/master/src/core/annotation.js#L79 is not a dictionary. However, if that were the case, it would break even before https://github.com/mozilla/pdf.js/pull/12516/files#diff-f0385d138acfe65f04aec809ad0522722883e56b6420ccb8f1d2e16b50631c1eR972, namely at https://github.com/mozilla/pdf.js/blob/master/src/core/document.js#L952-L953 as far as I can tell.

That's because the fieldRef we give to AnnotationLayer.create is the same fieldRef that we use just above to also fetch the T property, so if it's not a dictionary we wouldn't be able to call .has("T") on it.

@Snuffleupagus
Copy link
Collaborator Author

Are you sure this can actually happen?

It's more of a better safe than sorry sort of patch, since I think that it first of all makes general sense and secondly who knows what future code changes may bring. Good point though!

@timvandermeij timvandermeij merged commit c493dc9 into mozilla:master Oct 24, 2020
@timvandermeij
Copy link
Contributor

Thanks!

@Snuffleupagus Snuffleupagus deleted the fieldObjects-annotation-undefined branch October 24, 2020 14:26
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.

4 participants