]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
accel: Fix offset clamping in do_accel_block to not go before start (#365)
authorByeonguk Jeong <jungbu2855@gmail.com>
Fri, 3 Apr 2026 07:39:57 +0000 (16:39 +0900)
committerGitHub <noreply@github.com>
Fri, 3 Apr 2026 07:39:57 +0000 (10:39 +0300)
When applying the accel offset, the result was clamped to buf which
could produce a position before *start, potentially causing the caller
to re-scan bytes that were already processed. Clamp to ptr (buf +
*start) instead, so that the accelerator never rewinds past the original
start position.

src/hwlm/hwlm.c

index 3d3c0a713b273605fee2ee83dc162ab1a62321da..bf049d32760fab9c3137895f594e34ebecd7de1f 100644 (file)
@@ -97,16 +97,16 @@ void do_accel_block(const union AccelAux *aux, const u8 *buf, size_t len,
     const u8 *ptr = buf + *start;
     const u8 *end = buf + len;
     const u8 offset = aux->generic.offset;
-    ptr = run_hwlm_accel(aux, ptr, end);
+    const u8 *rv = run_hwlm_accel(aux, ptr, end);
 
     if (offset) {
-        ptr -= offset;
-        if (ptr < buf) {
-            ptr = buf;
+        rv -= offset;
+        if (rv < buf) {
+            rv = buf;
         }
     }
-    assert(ptr >= buf);
-    *start = ptr - buf;
+    assert(rv >= buf);
+    *start = rv - buf;
 }
 
 static really_inline