Skip to content

transform/subslice: Add subslice transform#14751

Open
jlucovsky wants to merge 2 commits intoOISF:mainfrom
jlucovsky:7672/13
Open

transform/subslice: Add subslice transform#14751
jlucovsky wants to merge 2 commits intoOISF:mainfrom
jlucovsky:7672/13

Conversation

@jlucovsky
Copy link
Contributor

Continuation of #14643

The subslice transform creates a slice of the input buffer.

Specify the subslice desired -- nbytes and truncate are optional:
        subslice: offset <,nbytes> <,truncate>

offset: Specifies the starting offset for the new subslice. When
negative, expresses how far from the end of the input buffer to begin.
When nbytes is *not* specified, start must be > 0.

nbytes: Specifies the size of the subslice. When negative, specifies the
byte count preceding the offset to include. Nbytes must be > 0.

When nbytes is not specified, the size of the subslice will be the size
of the input buffer - offset.

truncate: Specify behavior when offset + nbytes exceeds buffer length.
When present, trims nbytes such that offset + nbytes equals buffer
length. When not present, an empty buffer is produced.

Examples:
subslice: 1; - The subslice will be a copy of the input
buffer but omit the input buffer's first byte
"This is Suricata" -> "his is Suricata"
subslice: 0, 13; - The slice is created from the first 13 bytes
of the input buffer
"This is Suricata" -> "This is Suric"
subslice: 10, -5; - This is the same as subslice[5, 5]
"This is Suricata" -> "is Su"
subslice: -3; - The subslice will be the last 3 bytes of the
input buffer.
"This is Suricata" -> "ata"

Link to ticket: https://redmine.openinfosecfoundation.org/issues/7672

Describe changes:

  • Add subslice transform and unit tests
  • Document subslice transform, with examples

Updates:

  • Removed support for bracketed values, e.g., [3], [3, 8]`
  • Changed function DetectTransformSubsliceData to be attributed with repr(C)
  • Modified handling of negative nbyte values to mean "bytes from the end" .
  • start=0 is an error unless nbytes is specified
  • end=0 is always an error.
  • Corrected clippy issues.
  • Added configuration variable subslice.truncate to control behavior when offset + nbytes > length
  • Updated s-v branch.
  • Fixed s-v failing tests due to default config settings
  • Rebase
  • Fixed race condition in unittests wrt global variable
  • Removed truncate global option and replaced with a per-usage truncate option.
  • Rebase
  • Doc update to remove lingering global truncate option.
  • Removed commit that adjusted asn1 underline characters.
  • Updated Rust unit tests to eliminate is_some usage.
  • Removed inadvertent inclusion of Cargo.lock.in
  • Applied truncate option to negative offsets/byte count exceeding buffer length.
  • Reworked slice copy to handle input/output pointing to the same buffer.
  • Expanded documention to include discussion on negative offset/nbytes exceeding buffer length.

Provide values to any of the below to override the defaults.

  • To use a Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=OISF/suricata-verify#2749
SU_REPO=
SU_BRANCH=

Issue: 7672

The subslice transform creates a slice of the input buffer.

Specify the subslice desired -- nbytes and truncate are optional:
        subslice: offset <,nbytes> <,truncate>

offset: Specifies the starting offset for the new subslice. When
negative, expresses how far from the end of the input buffer to begin.
When nbytes is *not* specified, start must be > 0.

nbytes: Specifies the size of the subslice. When negative, specifies the
byte count preceding the offset to include. Nbytes must be > 0.

When nbytes is not specified, the size of the subslice will be the size
of the input buffer - offset.

truncate: Specify behavior when offset + nbytes exceeds buffer length.
When present, trims nbytes such that offset + nbytes equals buffer
length. When not present, an empty buffer is produced.

Examples:
        subslice: 1;     - The subslice will be a copy of the input
            buffer but omits the input buffer's first byte
            "This is Suricata" -> "his is Suricata"
        subslice: 0, 13; - The slice is created from the first 13 bytes
            of the input buffer
            "This is Suricata" -> "This is Suric"
        subslice: 10, -5; - The subslice is created starting at offset 10
            and continues to 5 bytes before the end of the input buffer
            "This is Suricata" -> "r"
        subslice: -3; - The subslice will be the last 3 bytes of the
            input buffer.
            "This is Suricata" -> "ata"
Add documentation for the subslice transform.

Issue: 7672
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 97.39414% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.20%. Comparing base (c1d6958) to head (6f58eb1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14751      +/-   ##
==========================================
+ Coverage   82.17%   82.20%   +0.03%     
==========================================
  Files        1008     1009       +1     
  Lines      263938   264552     +614     
==========================================
+ Hits       216878   217475     +597     
- Misses      47060    47077      +17     
Flag Coverage Δ
fuzzcorpus 60.15% <10.12%> (-0.05%) ⬇️
livemode 18.75% <10.12%> (+0.02%) ⬆️
netns 18.53% <10.19%> (-0.04%) ⬇️
pcap 44.60% <10.12%> (-0.04%) ⬇️
suricata-verify 65.38% <85.35%> (+0.02%) ⬆️
unittests 59.43% <90.86%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline = 29413

@catenacyber
Copy link
Contributor

Why is CI so red ? (rebase SV ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants