Repository: nvaccess/nvda

Issue:
Error when loading some virtual buffers in Firefox with newest Alpha builds
### Steps to reproduce:

1. In Firefox, load a few Bugzilla bugs from the Mozilla bug instance. This particular instance is special because it redirects to the start of the bug within the page after page load, does not start at the top.
2. You may have to repeat step 1 a few times, or load different bugs.

### Actual behavior:

Regularly, I get the below errors:

DEBUG - treeInterceptorHandler.update (08:35:25.569):
Adding new treeInterceptor to runningTable: <virtualBuffers.gecko_ia2.Gecko_ia2 object at 0x05DE2F90>
DEBUG - virtualBuffers.VirtualBuffer._loadBuffer (08:35:25.740):
Buffer load took 0.172 sec, 476 chars
DEBUGWARNING - RPC process 15020 (firefox.exe) (08:35:25.881):
Thread 4776, build\x86_64\vbufBase\storage.cpp, VBufStorage_buffer_t::findNodeByAttributes, 918:
 offset 476 is past end of buffer, returning NULL

DEBUGWARNING - RPC process 15020 (firefox.exe) (08:35:25.881):
Thread 4776, build\x86_64\vbufBase\storage.cpp, VBufStorage_buffer_t::locateTextFieldNodeAtOffset, 809:
Offset 476 out of range. Returnning NULL

DEBUGWARNING - RPC process 15020 (firefox.exe) (08:35:25.897):
Thread 4776, build\x86_64\vbufBase\storage.cpp, VBufStorage_buffer_t::locateControlFieldNodeAtOffset, 829:
Could not locate node at offset, returning NULL

DEBUGWARNING - RPC process 15020 (firefox.exe) (08:35:25.960):
Thread 15196, build\x86_64\vbufBase\storage.cpp, VBufStorage_buffer_t::locateTextFieldNodeAtOffset, 809:
Offset 476 out of range. Returnning NULL

DEBUGWARNING - RPC process 15020 (firefox.exe) (08:35:25.976):
Thread 15196, build\x86_64\vbufBase\storage.cpp, VBufStorage_buffer_t::locateControlFieldNodeAtOffset, 829:
Could not locate node at offset, returning NULL

ERROR - queueHandler.flushQueue (08:35:25.897):
Error in func _loadBufferDone from eventQueue
Traceback (most recent call last):
  File "queueHandler.pyc", line 53, in flushQueue
  File "virtualBuffers\__init__.pyc", line 460, in _loadBufferDone
  File "browseMode.pyc", line 1136, in event_treeInterceptor_gainFocus
  File "browseMode.pyc", line 1210, in _set_selection
  File "baseObject.pyc", line 21, in __get__
  File "textInfos\offsets.pyc", line 311, in _get_NVDAObjectAtStart
  File "virtualBuffers\__init__.pyc", line 181, in _getNVDAObjectFromOffset
  File "virtualBuffers\__init__.pyc", line 160, in _getFieldIdentifierFromOffset
LookupError: Neither docHandle nor ID found for offset 476
DEBUGWARNING - NVDAObjects.IAccessible.IAccessible._get_IAccessibleRole (08:35:27.076):
accRole failed: (-2147024809, 'Falscher Parameter.', (None, None, None, 0, None))
DEBUGWARNING - NVDAObjects.IAccessible.IAccessible._get_IAccessibleRole (08:35:27.092):
accRole failed: (-2147024809, 'Falscher Parameter.', (None, None, None, 0, None))
DEBUGWARNING - NVDAObjects.IAccessible.IAccessible._get_IAccessibleRole (08:35:27.108):
accRole failed: (-2147024809, 'Falscher Parameter.', (None, None, None, 0, None))
DEBUGWARNING - NVDAObjects.IAccessible.IAccessible._get_IAccessibleRole (08:35:27.388):
accRole failed: (-2147024809, 'Falscher Parameter.', (None, None, None, 0, None))
DEBUGWARNING - NVDAObjects.IAccessible.IAccessible._get_IAccessibleRole (08:35:27.404):
accRole failed: (-2147024809, 'Falscher Parameter.', (None, None, None, 0, None))

Speech is OK for the most part after this, but braille isn't. The braille display is blank, no text or structural information is shown. Also alt-tabbing out and back into Firefox doesn't fix the problem, I have to reload the page and then hope the next load will succeed.

### Expected behavior:

No errors.

### System configuration:

#### NVDA Installed/portable/running from source:

Installed.

#### NVDA version:

NVDA version alpha-15920,8e2df9fd

#### Windows version:

Version 1809 (Build 17744.1001)

#### Name and version of other software in use when reproducing the issue:

Firefox Nightly 63.0a1, latest build.

#### Other information about your system:

### Other questions:

#### Does the issue still occur after restarting your PC?

Yes.

#### Have you tried any other versions of NVDA?

Yes, NVDA 2018.2.1, but didn't see the issue there.

There are two things that changed recently. First, I have only started seeing this in the above mentioned Alpha version, not earlier. But at the same time, Firefox Nightly gained a new/reworked scrolling event which, although for Android, had some intermittent problems on Windows. However these have been fixed in the latest Nightly builds of Firefox, and I still see the issue.

CC'ing @leonardder @feerrenrut and @jcsteh who recently changed/reviewed things in the virtual buffer code.


Discussion:

Resolving patch:
diff --git a/source/virtualBuffers/__init__.py b/source/virtualBuffers/__init__.py
--- a/source/virtualBuffers/__init__.py
+++ b/source/virtualBuffers/__init__.py
@@ -178,7 +178,11 @@ def _getPointFromOffset(self,offset):
 		return textInfos.Point(left + width / 2, top + height / 2)
 
 	def _getNVDAObjectFromOffset(self,offset):
-		docHandle,ID=self._getFieldIdentifierFromOffset(offset)
+		try:
+			docHandle,ID=self._getFieldIdentifierFromOffset(offset)
+		except LookupError:
+			log.debugWarning("Couldn't get NVDAObject from offset %d" % offset)
+			return None
 		return self.obj.getNVDAObjectFromIdentifier(docHandle,ID)
 
 	def _getOffsetsFromNVDAObjectInBuffer(self,obj):


Test patch: