Skip to content

Fix crash in VBufStorage_buffer_t::getTextInRange when at the end of a buffer#8907

Merged
michaelDCurran merged 1 commit intomasterfrom
fixMergedVBufBackendLibsCrash
Nov 2, 2018
Merged

Fix crash in VBufStorage_buffer_t::getTextInRange when at the end of a buffer#8907
michaelDCurran merged 1 commit intomasterfrom
fixMergedVBufBackendLibsCrash

Conversation

@michaelDCurran
Copy link
Member

Link to issue number:

None.

Summary of the issue:

PR #8866 (merging of VBufBackends into nvdaHelperRemote) introduced a crash in VBufStorage_buffer_t::getTextInRange.
To reproduce:

  • Open Firefox
  • Go to URL: data:text/html,<p></p>
  • When focused in the document in browse mode, press right arrow and Firefox will crash.
    This is because VBufStorage_buffer_t::getTextInRange is declaired as returning a wstring, but on some errors it returns NULL. I am very surprised the compiler allows this.

Description of how this pull request fixes the issue:

This PR changes getTextInRange so that it takes a string by reference which it copies the text into, and it returns a bool communicating success or failure. Note that this is the way that the node-specific getTextInRange methods work already.

Testing performed:

In Firefox:

  • Arrowed up and down a standard html page with content.
  • Pressed right arrow on a completely blank page. There was no crash.

Known issues with pull request:

None.

Change log entry:

None needed.

Copy link
Contributor

@jcsteh jcsteh left a comment

Choose a reason for hiding this comment

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

Ouch! I too am... very surprised by the compiler.

wstring textString;
backend->getTextInRange(startOffset,endOffset,textString,useMarkup!=false);
backend->lock.release();
if(textString.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

backend->getTextInRange differentiates between "error" and "empty", but this function looks at "empty" to determine whether to return failure. Effectively, I think it amounts to the same thing, but it'd be good to be consistent, unless there's some reason you're deliberately checking empty instead of false here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it is safe to pass an empty string to sysAllocString? We could trust that if there was no error, the string is not empty... though I'd need to read the code much deeper to be sure that is always the case.

@michaelDCurran michaelDCurran merged commit 87eb36f into master Nov 2, 2018
@nvaccessAuto nvaccessAuto added this to the 2018.4 milestone Nov 2, 2018
}

wstring VBufStorage_buffer_t::getTextInRange(int startOffset, int endOffset, bool useMarkup) {
bool VBufStorage_buffer_t::getTextInRange(int startOffset, int endOffset, wstring& text, bool useMarkup) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I ask about the order of the params here? I would expect out params like text to be last?.

bool VBufStorage_buffer_t::getTextInRange(int startOffset, int endOffset, wstring& text, bool useMarkup) {
if(this->rootNode==NULL) {
LOG_DEBUGWARNING(L"buffer is empty, returning NULL");
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively this could just return empty strings in this case.

@jcsteh
Copy link
Contributor

jcsteh commented Nov 6, 2018

Just for reference, a Mozilla bug was filed for this crash: https://bugzilla.mozilla.org/show_bug.cgi?id=1504272

I've now closed it.

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.

4 participants