Skip to content

IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (#10227)#10231

Merged
michaelDCurran merged 3 commits into
nvaccess:masterfrom
accessolutions:i10227-ia2Base64
Sep 24, 2019
Merged

IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (#10227)#10231
michaelDCurran merged 3 commits into
nvaccess:masterfrom
accessolutions:i10227-ia2Base64

Conversation

@JulienCochuyt

Copy link
Copy Markdown
Contributor

Link to issue number:

Python side of #10227

Summary of the issue:

Huge base64 embedded in the src attribute of an img element can freeze Google Chrome.

Description of how this pull request fixes the issue:

When the IA2 attribute string exceeds a threshold of 4096 characters, truncate the base64 from the text passed to IAccessibleHandler.splitIA2Attribs before treating it.

Testing performed:

Known issues with pull request:

The huge base64 is still uselessly present in the Virtual Buffer data.
The NVDAHelper thus would probably benefit from an impact on that regard.

Change log entry:

Section: Bug fixes

NVDA no longer crashes in Google Chrome when an image contains huge base64 data.

@JulienCochuyt JulienCochuyt force-pushed the i10227-ia2Base64 branch 3 times, most recently from 006c574 to 5472fa7 Compare September 17, 2019 09:12
@JulienCochuyt JulienCochuyt marked this pull request as ready for review September 17, 2019 09:15
@LeonarddeR

Copy link
Copy Markdown
Collaborator

It is not clear to me how this pr stops Chrome from crashing.

@JulienCochuyt

JulienCochuyt commented Sep 17, 2019

Copy link
Copy Markdown
Contributor Author

It is not clear to me how this pr stops Chrome from crashing.

Chrome does not crash. NVDA freezes. My bad, I rephrased the title.
I fully agree this quick and dirty fix is not ideal, but it does solve at least our faulty real life scenario.
By dramatically reducing the size of the string to process, it avoids IAccessibleHandler.splitIA2Attribs taking to long to process when the incriminated element gets focus.
Any better solution would be very welcome.

@JulienCochuyt JulienCochuyt changed the title IA2: Do not treat huge base64 data as it might freeze Google Chrome (#10227) IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (#10227) Sep 17, 2019
@michaelDCurran

Copy link
Copy Markdown
Member

As this would impact any Assistive Technology, I really think this should be reported to and fixed in both Firefox and Google Chrome itself. They should not be exposing data:image URIs via IAccessible2 attributes.

@JulienCochuyt

Copy link
Copy Markdown
Contributor Author

As this would impact any Assistive Technology, I really think this should be reported to and fixed in both Firefox and Google Chrome itself. They should not be exposing data:image URIs via IAccessible2 attributes.

I agree, despite someone might nitpick with a convoluted use case.
I guess @jcsteh is the one of us with the better grasp of Firefox bug reports.
Do you know of someone involved in chromium?

Nevertheless, we should IMHO pragmatically implement this workaround (or another) in NVDA in the meantime.
For the record, we already did it in the same context as of #4793 back in 2015.

@michaelDCurran

Copy link
Copy Markdown
Member

I don't think it will be too hard to do this also in the Gecko vbufBackend for this pr.
At line 536 of nvdaHelper/vbufBackends/gecko_ia2/gecko_ia2.cpp
You'll want to create a c++ regex object matching on base64 similar to what you did in Python, and then use regex_replace, before passing the string to ia2AttribsToMap.
Note that we probably shouldn't do it directly inside ia2AttribsToMap as that function is also used for IAccessible2 text attribute parsing.

Comment thread source/IAccessibleHandler.py Outdated
@jcsteh

jcsteh commented Sep 24, 2019

Copy link
Copy Markdown
Contributor

As this would impact any Assistive Technology, I really think this should be reported to and fixed in both Firefox and Google Chrome itself. They should not be exposing data:image URIs via IAccessible2 attributes.

That's fair. What would you prefer we exposed? The obvious solution is not to expose the src attribute at all in this case. On the other hand, the presence of the src attribute might be meaningful (i.e. this image came from a URL).

@michaelDCurran

michaelDCurran commented Sep 24, 2019 via email

Copy link
Copy Markdown
Member

JulienCochuyt added a commit to accessolutions/nvda that referenced this pull request Sep 24, 2019
@michaelDCurran michaelDCurran merged commit 7bd4bf7 into nvaccess:master Sep 24, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Sep 24, 2019
michaelDCurran added a commit that referenced this pull request Sep 24, 2019
michaelDCurran pushed a commit that referenced this pull request Sep 24, 2019
…ome (#10227) - Py2 backport to beta (#10240)

* IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (#10227)

* Refine comment

Review action #10231 (comment)
@JulienCochuyt JulienCochuyt deleted the i10227-ia2Base64 branch September 25, 2019 06:55
@JulienCochuyt

Copy link
Copy Markdown
Contributor Author

Note that we probably shouldn't do it directly inside ia2AttribsToMap as that function is also used for IAccessible2 text attribute parsing.

@michaelDCurran, is there any chance that on the Python side IAccessibleHandler.splitIA2Attribs also receive text of any kind?
If so, I'm afraid the regex should be replaced by something like
r"(([^\\](\\\\)*);src:data\\:[^\\;]+\\;base64)\\,[A-Za-z0-9+/=]+"
and the replacement parameter by r"\1<truncated>".

As for the vbuf impact:
I used a regex on the Python side because it was processed in C and thus had a lesser performance cost than the current custom parsing of the string.
In C++, however, I believe it is the opposite: matching a regex is probably more time consuming than the current custom parsing of the string.
I think that appending a test of the value for the "src" attribute at the end of IA2AttribsToMap would be just fine, unless of course if you know of another use of the "src" attribute.
What do you think?

@michaelDCurran

michaelDCurran commented Sep 25, 2019 via email

Copy link
Copy Markdown
Member

@JulienCochuyt

Copy link
Copy Markdown
Contributor Author

@michaelDCurran
I prepared two alternatives for the vbuf impact:

I feel the first one (IA2AttribsToMap) is more logical and future-proof as live regions handling also uses this, but I've included the GeckoVBufBackend_t::fillVBuf as you foresaw it would have your preference.
They are otherwise quite identical and I've successfully tested both of them with Firefox and Chrome.
Please let me know if either suits your expectations and I'll file a PR accordingly.

JulienCochuyt added a commit to accessolutions/nvda that referenced this pull request Sep 26, 2019
… Google Chrome (PR nvaccess#10231)

Ensure to truncate base64 data only in the `src` attribute, and not in an eventual
text content (eg. in and inline editor).

Re: nvaccess#10231 (comment)
JulienCochuyt added a commit to accessolutions/nvda that referenced this pull request Sep 26, 2019
… Google Chrome (PR nvaccess#10231)

Ensure to truncate base64 data only in the `src` attribute, and not in an eventual
text content (eg. in and inline editor).

Re: nvaccess#10231 (comment)
JulienCochuyt added a commit to accessolutions/nvda that referenced this pull request Sep 26, 2019
… Google Chrome (PR nvaccess#10240)

Ensure to truncate base64 data only in the `src` attribute, and not in an eventual
text content (eg. in and inline editor).

Re: nvaccess#10231 (comment)
michaelDCurran pushed a commit that referenced this pull request Sep 30, 2019
… Google Chrome (PR #10231) (#10281)

* Fix up of: IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (PR #10231)

Ensure to truncate base64 data only in the `src` attribute, and not in an eventual
text content (eg. in and inline editor).

Re: #10231 (comment)

* Fix up of db3ec56: Include the comma after "base64" in the capturing group
michaelDCurran pushed a commit that referenced this pull request Sep 30, 2019
… Google Chrome (PR #10240) (#10282)

* Fix up of: IA2: Do not treat huge base64 data as NVDA might freeze in Google Chrome (PR #10240)

Ensure to truncate base64 data only in the `src` attribute, and not in an eventual
text content (eg. in and inline editor).

Re: #10231 (comment)

* Fix up of bd35387: Include the comma after "base64" in the capturing group
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.

5 participants