Skip to content

Fix assertion failure for bounded repeat of exactly MAX_REPEAT#456

Open
LuciferDono wants to merge 1 commit intointel:masterfrom
LuciferDono:fix/bounded-repeat-32767
Open

Fix assertion failure for bounded repeat of exactly MAX_REPEAT#456
LuciferDono wants to merge 1 commit intointel:masterfrom
LuciferDono:fix/bounded-repeat-32767

Conversation

@LuciferDono
Copy link

Summary

Fixes an assertion failure (crash) when compiling a pattern with a bounded repeat of exactly 32767 (MAX_REPEAT).

The constructor in ComponentRepeat validates with m_max > MAX_REPEAT, correctly allowing 32767 as a valid value. However, the assertion in notePositions() uses m_max < MAX_REPEAT, which rejects 32767 and triggers an abort.

Fixes #425

Reproduction

import hyperscan
db = hyperscan.Database(mode=hyperscan.HS_MODE_STREAM)
db.compile(expressions=[b'abc .{0,32767}'])  # assertion failure / crash
  • {0,32766} compiles successfully
  • {0,32768} returns a proper "Bounded repeat is too large" error
  • {0,32767} crashes with: Assertion 'm_max == NoLimit || m_max < MAX_REPEAT' failed

Change

One-character fix in src/parser/ComponentRepeat.cpp:

-    assert(m_max == NoLimit || m_max < MAX_REPEAT);
+    assert(m_max == NoLimit || m_max <= MAX_REPEAT);

This makes the assertion consistent with the constructor's boundary validation on lines 71-76 of the same file.

Pattern `abc .{0,32767}` causes an assertion failure in
ComponentRepeat::notePositions() because the assertion uses strict
less-than (m_max < MAX_REPEAT) while the constructor validates with
greater-than (m_max > MAX_REPEAT), creating an off-by-one gap at
exactly MAX_REPEAT (32767).

Change the assertion to use <= to match the constructor's boundary,
allowing the valid value of 32767 through without crashing.

Fixes intel#425
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.

Hyperscan panics if bounded repeat is exactly 32767

1 participant