Skip to content

python: reject non-contiguous buffers - #655

Open
mraimadeddinehouas-glitch wants to merge 1 commit into
google:mainfrom
mraimadeddinehouas-glitch:python-buffer-validation-fix
Open

python: reject non-contiguous buffers#655
mraimadeddinehouas-glitch wants to merge 1 commit into
google:mainfrom
mraimadeddinehouas-glitch:python-buffer-validation-fix

Conversation

@mraimadeddinehouas-glitch

Copy link
Copy Markdown

The Python binding requests a full buffer view but previously treated every buffer as a contiguous one-dimensional byte string. This is unsafe for non-contiguous, multi-dimensional, or wider-item buffers: the pointer arithmetic and byte length do not describe the logical view.

This change validates the buffer layout before constructing an absl::string_view. Unsupported layouts are rejected unless the buffer is one-dimensional, byte-sized, and has a unit stride.

A regression test covers reversed and strided memoryviews for both pattern and input paths.

Validation:

  • RE2 C++ CMake suite: 20/20 tests passed.
    • Python binding suite: 244 tests passed.
    • Independent comparison: the parent revision accepted strided, reversed, two-dimensional, and wide-item buffers; this revision rejects all four.
    • No upstream source files outside the Python binding and its tests are changed.

@google-cla

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mraimadeddinehouas-glitch
mraimadeddinehouas-glitchforce-pushed the python-buffer-validation-fix branch 2 times, most recently from 1b1bcd3 to 641edd9CompareAugust 28, 2026 02:17
@mraimadeddinehouas-glitch

Copy link
Copy Markdown
Author

Hello RE2 maintainers — when convenient, could you please review this PR? The patch is narrowly scoped to the Python binding, the C++ and Python test suites pass, the Google CLA check passes, and the commit is verified. The PR is ready for review; thank you.

Sign up for freeto 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

@mraimadeddinehouas-glitch