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

Regex processing using {n,m} repeat syntax is off by one #1632

Closed
kkvarfordt opened this issue Jan 3, 2024 · 2 comments · Fixed by rsmmr/justrx#8 or #1636
Closed

Regex processing using {n,m} repeat syntax is off by one #1632

kkvarfordt opened this issue Jan 3, 2024 · 2 comments · Fixed by rsmmr/justrx#8 or #1636
Assignees
Labels
Bug Something isn't working

Comments

@kkvarfordt
Copy link

If you have a unit that has a 4 byte field followed by 0 to 3 null bytes, but the input has 5 null bytes on the end, the resulting output shows 4 null bytes when it should be 3 null bytes. See the following code for details.

Version: spicy-driver v1.9.0 (7b8eff5)

Code:

module Test;
import spicy;

public type Foo = unit {
    field_1: bytes &size=4;
    field_2: /\x00{0,3}/;

    on %done {
        print "field_1 => %x" % self.field_1;
        print "field_2 => %x" % self.field_2;
    }
}

Command:
printf '\01\02\03\04\00\00\00\00\00' | spicy-driver regex-broken-repeat-syntax.spicy

Result:

clang: warning: -lc++abi: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lc++abi: 'linker' input unused [-Wunused-command-line-argument]
field_1 => \x01\x02\x03\x04
field_2 => \x00\x00\x00\x00
@bbannier bbannier added the Bug Something isn't working label Jan 4, 2024
@bbannier
Copy link
Member

bbannier commented Jan 4, 2024

Thank you for the ticket.

Interestingly at least for this reproducer this seems to work for max lengths 1 and 2, and fail for any other max length.

module foo;

assert |*b"\x00\x00\x00\x00\x00\x00\x00".match(/\x00{0,1}/)| == 1; # WORKS.
assert |*b"\x00\x00\x00\x00\x00\x00\x00".match(/\x00{0,2}/)| == 2; # WORKS.
assert |*b"\x00\x00\x00\x00\x00\x00\x00".match(/\x00{0,3}/)| == 3; # FAILS.
assert |*b"\x00\x00\x00\x00\x00\x00\x00".match(/\x00{0,4}/)| == 4; # FAILS.
assert |*b"\x00\x00\x00\x00\x00\x00\x00".match(/\x00{0,5}/)| == 5; # FAILS.

@bbannier
Copy link
Member

bbannier commented Jan 4, 2024

Since this very likely is in https://github.com/rsmmr/justrx, is this something you could look into @rsmmr?

@rsmmr rsmmr self-assigned this Jan 4, 2024
rsmmr added a commit that referenced this issue Jan 5, 2024
rsmmr added a commit that referenced this issue Jan 8, 2024
rsmmr added a commit that referenced this issue Jan 9, 2024
rsmmr added a commit that referenced this issue Jan 9, 2024
* origin/topic/robin/gh-1632-regex-fix:
  Bump justrx to pull in bugfix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants