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

BUGFIX (definitive) for regex search matching deleted text #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnwait
Copy link
Owner

@johnwait johnwait commented Aug 17, 2024

Reverts the bug-fixing workaround introduced as part of commit f751537 that required to modify Scintilla's own code base by adding new members to the Scintilla::Document(), Scintilla::CellBuffer() & Scintilla::SplitVector() class.

Quick recap on the bug

The bug arose from the need to plug the new regular expression engine, Onigmo, into Scintilla's built-in RegexSearchBase interface for its use as a custom regex engine. While the Onimo engine expects to have direct access to a text buffer to search from, Scintilla can provide such access but care must be taken as Scintilla, internally, uses a gap buffer and its location must be considered when reading characters from it, as it can lead to false positives when searching for regex matches, although in very specific, edge cases.

For example, if characters were to be suppressed from the end of an existing using the <Backspace> key, then searching with regex pattern that would otherwise have captured both those suppressed characters—but not, incidentally and in such very specific cases, that same end of line without those now-suppressed chars—would effectively find a match for that end of line, erroneously, simply because those suppressed chars remain in Scintilla's gap buffer until their effective removal is triggered by moving the insertion cursor elsewhere of until the text is changed elsewhere in the open document.

The original solution was to patch Scintilla's own code directly by cloning the existing CellBuffer::RangePointer() into a new method, CellBuffer::DataPointer() (as well as for its analog on the Document interface) , with the difference that that new method would actively move the buffer gap out of the way / at the end of the range specified in the method call, such that the pointer returned would always be for a contiguous block of text.

Although negating the performance benefit of having a buffer gap (but with the penalty only occurring when initiating a search), the real problem with the original fix is that it changed directly Scintilla's code, and as such any in-place upgrade of Scintilla is « impossible » (i.e. causes a regression of the bug) unless the fix is replicated on Scintilla's updated codebase, if it can be at all.

The definitive fix of the bug

The need for updating Scintilla's code is pretty much a given, for the simple reason that doing so fixes many other bugs but also patches known security vulnerabilities. While contemplating such update, finding a more permanent fix (or workaround) for the bug became a priority.

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.

1 participant