diff -pruN 5.4.0-2/CHANGELOG.md 5.4.2-1/CHANGELOG.md
--- 5.4.0-2/CHANGELOG.md	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/CHANGELOG.md	2023-04-19 09:34:39.000000000 +0000
@@ -2,6 +2,31 @@
 
 This is a list of notable changes to Hyperscan, in reverse chronological order.
 
+## [5.4.2] 2023-04-19
+- Roll back bugfix for github issue #350: Besides using scratch for
+  corresponding database, Hyperscan also allows user to use larger scratch
+  allocated for another database. Users can leverage this property to achieve
+  safe scratch usage in multi-database scenarios. Behaviors beyond these are
+  discouraged and results are undefined.
+- Fix hsdump issue due to invalid nfa type.
+
+## [5.4.1] 2023-02-20
+- The Intel Hyperscan team is pleased to provide a bug fix release to our open source library.
+  Intel also maintains an upgraded version available through your Intel sales representative.
+- Bugfix for issue #184: fix random char value of UTF-8.
+- Bugfix for issue #291: bypass logical combination flag in hs_expression_info().
+- Bugfix for issue #292: fix build error due to libc symbol parsing.
+- Bugfix for issue #302/304: add empty string check for pure literal API.
+- Bugfix for issue #303: fix unknown instruction error in pure literal API.
+- Bugfix for issue #303: avoid memory leak in stream close stage.
+- Bugfix for issue #305: fix assertion failure in DFA construction.
+- Bugfix for issue #317: fix aligned allocator segment faults.
+- Bugfix for issue #350: add quick validity check for scratch.
+- Bugfix for issue #359: fix glibc-2.34 stack size issue.
+- Bugfix for issue #360: fix SKIP flag issue in chimera.
+- Bugfix for issue #362: fix one cotec check corner issue in UTF-8 validation.
+- Fix other compile issues.
+
 ## [5.4.0] 2020-12-31
 - Improvement on literal matcher "Fat Teddy" performance, including
   support for Intel(R) AVX-512 Vector Byte Manipulation Instructions (Intel(R)
diff -pruN 5.4.0-2/CMakeLists.txt 5.4.2-1/CMakeLists.txt
--- 5.4.0-2/CMakeLists.txt	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/CMakeLists.txt	2023-04-19 09:34:39.000000000 +0000
@@ -3,7 +3,7 @@ project (hyperscan C CXX)
 
 set (HS_MAJOR_VERSION 5)
 set (HS_MINOR_VERSION 4)
-set (HS_PATCH_VERSION 0)
+set (HS_PATCH_VERSION 2)
 set (HS_VERSION ${HS_MAJOR_VERSION}.${HS_MINOR_VERSION}.${HS_PATCH_VERSION})
 
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
@@ -397,6 +397,18 @@ if (CXX_UNUSED_CONST_VAR)
     set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-unused-const-variable")
 endif()
 
+# clang-14 complains about unused-but-set variable.
+CHECK_CXX_COMPILER_FLAG("-Wunused-but-set-variable" CXX_UNUSED_BUT_SET_VAR)
+if (CXX_UNUSED_BUT_SET_VAR)
+    set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-unused-but-set-variable")
+endif()
+
+# clang-14 complains about using bitwise operator instead of logical ones.
+CHECK_CXX_COMPILER_FLAG("-Wbitwise-instead-of-logical" CXX_BITWISE_INSTEAD_OF_LOGICAL)
+if (CXX_BITWISE_INSTEAD_OF_LOGICAL)
+    set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-bitwise-instead-of-logical")
+endif()
+
 # gcc 6 complains about type attributes that get ignored, like alignment
 CHECK_CXX_COMPILER_FLAG("-Wignored-attributes" CXX_IGNORED_ATTR)
 if (CXX_IGNORED_ATTR)
@@ -428,8 +440,10 @@ CHECK_CXX_COMPILER_FLAG("-Wunused-variab
 
 # gcc 10 complains about this
 CHECK_C_COMPILER_FLAG("-Wstringop-overflow" CC_STRINGOP_OVERFLOW)
-if(CC_STRINGOP_OVERFLOW)
+CHECK_CXX_COMPILER_FLAG("-Wstringop-overflow" CXX_STRINGOP_OVERFLOW)
+if(CC_STRINGOP_OVERFLOW OR CXX_STRINGOP_OVERFLOW)
     set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-stringop-overflow")
+    set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-stringop-overflow")
 endif()
 
 endif()
@@ -579,7 +593,7 @@ set (hs_exec_common_SRCS
 
 set (hs_exec_SRCS
     ${hs_HEADERS}
-    src/hs_version.h
+    src/hs_version.h.in
     src/ue2common.h
     src/allocator.h
     src/crc32.c
@@ -736,7 +750,7 @@ SET (hs_compile_SRCS
     src/grey.h
     src/hs.cpp
     src/hs_internal.h
-    src/hs_version.h
+    src/hs_version.h.in
     src/scratch.h
     src/state.h
     src/ue2common.h
diff -pruN 5.4.0-2/chimera/ch_runtime.c 5.4.2-1/chimera/ch_runtime.c
--- 5.4.0-2/chimera/ch_runtime.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/chimera/ch_runtime.c	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Intel Corporation
+ * Copyright (c) 2018-2022, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -326,6 +326,10 @@ ch_error_t catchupPcre(struct HybridCont
         } else if (cbrv == CH_CALLBACK_SKIP_PATTERN) {
             DEBUG_PRINTF("user callback told us to skip this pattern\n");
             pd->scanStart = hyctx->length;
+            if (top_id == id) {
+                break;
+            }
+            continue;
         }
 
         if (top_id == id) {
diff -pruN 5.4.0-2/cmake/build_wrapper.sh 5.4.2-1/cmake/build_wrapper.sh
--- 5.4.0-2/cmake/build_wrapper.sh	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/cmake/build_wrapper.sh	2023-04-19 09:34:39.000000000 +0000
@@ -17,7 +17,7 @@ KEEPSYMS=$(mktemp -p /tmp keep.syms.XXXX
 LIBC_SO=$("$@" --print-file-name=libc.so.6)
 cp ${KEEPSYMS_IN} ${KEEPSYMS}
 # get all symbols from libc and turn them into patterns
-nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ ]*\).*/^\1$/' >> ${KEEPSYMS}
+nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ @]*\).*/^\1$/' >> ${KEEPSYMS}
 # build the object
 "$@"
 # rename the symbols in the object
diff -pruN 5.4.0-2/debian/changelog 5.4.2-1/debian/changelog
--- 5.4.0-2/debian/changelog	2021-01-26 08:35:39.000000000 +0000
+++ 5.4.2-1/debian/changelog	2023-05-20 09:55:57.000000000 +0000
@@ -1,3 +1,11 @@
+hyperscan (5.4.2-1) unstable; urgency=medium
+
+  * Fix debian/watch for new github api
+  * Remove patches (included by upstream)
+  * New upstream version 5.4.2
+
+ -- Robert Haist <rha@debian.org>  Sat, 20 May 2023 11:55:57 +0200
+
 hyperscan (5.4.0-2) unstable; urgency=medium
 
   * Add upstream patch for i386 builds
diff -pruN 5.4.0-2/debian/patches/0001-Small-upstream-fix-to-the-cmake-build-system.patch 5.4.2-1/debian/patches/0001-Small-upstream-fix-to-the-cmake-build-system.patch
--- 5.4.0-2/debian/patches/0001-Small-upstream-fix-to-the-cmake-build-system.patch	2021-01-26 08:35:39.000000000 +0000
+++ 5.4.2-1/debian/patches/0001-Small-upstream-fix-to-the-cmake-build-system.patch	1970-01-01 00:00:00.000000000 +0000
@@ -1,21 +0,0 @@
-From: Robert Haist <rhaist@mailbox.org>
-Date: Tue, 19 Jan 2021 17:00:22 +0100
-Subject: Small upstream fix to the cmake build system
-
----
- cmake/build_wrapper.sh | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/cmake/build_wrapper.sh b/cmake/build_wrapper.sh
-index 1962813..895610c 100755
---- a/cmake/build_wrapper.sh
-+++ b/cmake/build_wrapper.sh
-@@ -17,7 +17,7 @@ KEEPSYMS=$(mktemp -p /tmp keep.syms.XXXXX)
- LIBC_SO=$("$@" --print-file-name=libc.so.6)
- cp ${KEEPSYMS_IN} ${KEEPSYMS}
- # get all symbols from libc and turn them into patterns
--nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ ]*\).*/^\1$/' >> ${KEEPSYMS}
-+nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ @]*\).*/^\1$/' >> ${KEEPSYMS}
- # build the object
- "$@"
- # rename the symbols in the object
diff -pruN 5.4.0-2/debian/patches/0002-fix-missing-instruction.patch 5.4.2-1/debian/patches/0002-fix-missing-instruction.patch
--- 5.4.0-2/debian/patches/0002-fix-missing-instruction.patch	2021-01-26 08:35:39.000000000 +0000
+++ 5.4.2-1/debian/patches/0002-fix-missing-instruction.patch	1970-01-01 00:00:00.000000000 +0000
@@ -1,61 +0,0 @@
-From 52a698b0e134f0c29984ecbd0a885744d20812c1 Mon Sep 17 00:00:00 2001
-From: Wang Xiang W <xiang.w.wang@intel.com>
-Date: Tue, 26 Jan 2021 11:43:27 +0000
-Subject: [PATCH] fix missing instruction
-
----
- src/util/simd_utils.h | 24 ++++++++++++------------
- 1 file changed, 12 insertions(+), 12 deletions(-)
-
-diff --git a/src/util/simd_utils.h b/src/util/simd_utils.h
-index d1f060b0..5d5ddaf1 100644
---- a/src/util/simd_utils.h
-+++ b/src/util/simd_utils.h
-@@ -156,6 +156,16 @@ static really_inline u32 movd(const m128 in) {
-     return _mm_cvtsi128_si32(in);
- }
- 
-+static really_inline u64a movq(const m128 in) {
-+#if defined(ARCH_X86_64)
-+    return _mm_cvtsi128_si64(in);
-+#else // 32-bit - this is horrific
-+    u32 lo = movd(in);
-+    u32 hi = movd(_mm_srli_epi64(in, 32));
-+    return (u64a)hi << 32 | lo;
-+#endif
-+}
-+
- #if defined(HAVE_AVX512)
- static really_inline u32 movd512(const m512 in) {
-     // NOTE: seems gcc doesn't support _mm512_cvtsi512_si32(in),
-@@ -166,20 +176,10 @@ static really_inline u32 movd512(const m512 in) {
- static really_inline u64a movq512(const m512 in) {
-     // NOTE: seems AVX512 doesn't support _mm512_cvtsi512_si64(in),
-     //       so we use 2-step convertions to work around.
--    return _mm_cvtsi128_si64(_mm512_castsi512_si128(in));
-+    return movq(_mm512_castsi512_si128(in));
- }
- #endif
- 
--static really_inline u64a movq(const m128 in) {
--#if defined(ARCH_X86_64)
--    return _mm_cvtsi128_si64(in);
--#else // 32-bit - this is horrific
--    u32 lo = movd(in);
--    u32 hi = movd(_mm_srli_epi64(in, 32));
--    return (u64a)hi << 32 | lo;
--#endif
--}
--
- /* another form of movq */
- static really_inline
- m128 load_m128_from_u64a(const u64a *p) {
-@@ -791,7 +791,7 @@ m128 movdq_lo(m256 x) {
- #define lshift128_m256(a, count_immed) _mm256_slli_si256(a, count_immed)
- #define extract64from256(a, imm) _mm_extract_epi64(_mm256_extracti128_si256(a, imm >> 1), imm % 2)
- #define extract32from256(a, imm) _mm_extract_epi32(_mm256_extracti128_si256(a, imm >> 2), imm % 4)
--#define extractlow64from256(a) _mm_cvtsi128_si64(cast256to128(a))
-+#define extractlow64from256(a) movq(cast256to128(a))
- #define extractlow32from256(a) movd(cast256to128(a))
- #define interleave256hi(a, b) _mm256_unpackhi_epi8(a, b)
- #define interleave256lo(a, b) _mm256_unpacklo_epi8(a, b)
diff -pruN 5.4.0-2/debian/patches/series 5.4.2-1/debian/patches/series
--- 5.4.0-2/debian/patches/series	2021-01-26 08:35:39.000000000 +0000
+++ 5.4.2-1/debian/patches/series	1970-01-01 00:00:00.000000000 +0000
@@ -1,2 +0,0 @@
-0001-Small-upstream-fix-to-the-cmake-build-system.patch
-0002-fix-missing-instruction.patch
diff -pruN 5.4.0-2/debian/watch 5.4.2-1/debian/watch
--- 5.4.0-2/debian/watch	2021-01-26 08:35:39.000000000 +0000
+++ 5.4.2-1/debian/watch	2023-05-20 09:55:57.000000000 +0000
@@ -1,4 +1,5 @@
 version=4
-opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%<project>-$1.tar.gz%" \
-    https://github.com/intel/hyperscan/releases \
-    (?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian uupdate
+opts="searchmode=plain,\
+filenamemangle=s%v?@ANY_VERSION@%@PACKAGE@-$1.tar.xz%" \
+https://api.github.com/repos/intel/hyperscan/releases?per_page=50 \
+https://api.github.com/repos/[^/]+/[^/]+/tarball/v?@ANY_VERSION@
diff -pruN 5.4.0-2/examples/patbench.cc 5.4.2-1/examples/patbench.cc
--- 5.4.0-2/examples/patbench.cc	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/examples/patbench.cc	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -115,6 +115,7 @@
 #include <algorithm>
 #include <cstring>
 #include <chrono>
+#include <climits>
 #include <fstream>
 #include <iomanip>
 #include <iostream>
@@ -657,6 +658,10 @@ int main(int argc, char **argv) {
             break;
         case 'n':
             repeatCount = atoi(optarg);
+            if (repeatCount <= 0 || repeatCount > UINT_MAX) {
+                cerr << "Invalid repeatCount." << endl;
+                exit(-1);
+            }
             break;
         default:
             usage(argv[0]);
diff -pruN 5.4.0-2/examples/pcapscan.cc 5.4.2-1/examples/pcapscan.cc
--- 5.4.0-2/examples/pcapscan.cc	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/examples/pcapscan.cc	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -51,6 +51,7 @@
 
 #include <cstring>
 #include <chrono>
+#include <climits>
 #include <fstream>
 #include <iomanip>
 #include <iostream>
@@ -489,6 +490,10 @@ int main(int argc, char **argv) {
 
     // Streaming mode scans.
     double secsStreamingScan = 0.0, secsStreamingOpenClose = 0.0;
+    if (repeatCount <= 0 || repeatCount > UINT_MAX) {
+        cerr << "Invalid repeatCount." << endl;
+        exit(-1);
+    }
     for (unsigned int i = 0; i < repeatCount; i++) {
         // Open streams.
         clock.start();
diff -pruN 5.4.0-2/examples/simplegrep.c 5.4.2-1/examples/simplegrep.c
--- 5.4.0-2/examples/simplegrep.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/examples/simplegrep.c	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -57,6 +57,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <hs.h>
 
@@ -152,6 +153,15 @@ int main(int argc, char *argv[]) {
     char *pattern = argv[1];
     char *inputFN = argv[2];
 
+    if (access(inputFN, F_OK) != 0) {
+        fprintf(stderr, "ERROR: file doesn't exist.\n");
+        return -1;
+    }
+    if (access(inputFN, R_OK) != 0) {
+        fprintf(stderr, "ERROR: can't be read.\n");
+        return -1;
+    }
+
     /* First, we attempt to compile the pattern provided on the command line.
      * We assume 'DOTALL' semantics, meaning that the '.' meta-character will
      * match newline characters. The compiler will analyse the given pattern and
diff -pruN 5.4.0-2/src/compiler/compiler.cpp 5.4.2-1/src/compiler/compiler.cpp
--- 5.4.0-2/src/compiler/compiler.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/compiler/compiler.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -323,7 +323,8 @@ void addExpression(NG &ng, unsigned inde
     }
 
     // Ensure that our pattern isn't too long (in characters).
-    if (strlen(expression) > cc.grey.limitPatternLength) {
+    size_t maxlen = cc.grey.limitPatternLength + 1;
+    if (strnlen(expression, maxlen) >= maxlen) {
         throw CompileError("Pattern length exceeds limit.");
     }
 
@@ -416,6 +417,10 @@ void addLitExpression(NG &ng, unsigned i
                            "HS_FLAG_SOM_LEFTMOST are supported in literal API.");
     }
 
+    if (!strcmp(expression, "")) {
+        throw CompileError("Pure literal API doesn't support empty string.");
+    }
+
     // This expression must be a pure literal, we can build ue2_literal
     // directly based on expression text.
     ParsedLitExpression ple(index, expression, expLength, flags, id);
diff -pruN 5.4.0-2/src/hs.cpp 5.4.2-1/src/hs.cpp
--- 5.4.0-2/src/hs.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/hs.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -514,6 +514,12 @@ hs_error_t hs_expression_info_int(const
         return HS_COMPILER_ERROR;
     }
 
+    if (flags & HS_FLAG_COMBINATION) {
+        *error = generateCompileError("Invalid parameter: unsupported "
+                                      "logical combination expression", -1);
+        return HS_COMPILER_ERROR;
+    }
+
     *info = nullptr;
     *error = nullptr;
 
diff -pruN 5.4.0-2/src/hs.h 5.4.2-1/src/hs.h
--- 5.4.0-2/src/hs.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/hs.h	2023-04-19 09:34:39.000000000 +0000
@@ -43,7 +43,7 @@
 
 #define HS_MAJOR      5
 #define HS_MINOR      4
-#define HS_PATCH      0
+#define HS_PATCH      2
 
 #include "hs_compile.h"
 #include "hs_runtime.h"
diff -pruN 5.4.0-2/src/hs_compile.h 5.4.2-1/src/hs_compile.h
--- 5.4.0-2/src/hs_compile.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/hs_compile.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -748,10 +748,7 @@ hs_error_t HS_CDECL hs_free_compile_erro
  *       - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode.
  *       - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset
  *                                when a match is found.
- *       - HS_FLAG_COMBINATION - Parse the expression in logical combination
- *                               syntax.
- *       - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for
- *                         the sub-expressions in logical combinations.
+ *       - HS_FLAG_QUIET - This flag will be ignored.
  *
  * @param info
  *      On success, a pointer to the pattern information will be returned in
@@ -814,10 +811,7 @@ hs_error_t HS_CDECL hs_expression_info(c
  *       - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode.
  *       - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset
  *                                when a match is found.
- *       - HS_FLAG_COMBINATION - Parse the expression in logical combination
- *                               syntax.
- *       - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for
- *                         the sub-expressions in logical combinations.
+ *       - HS_FLAG_QUIET - This flag will be ignored.
  *
  * @param ext
  *      A pointer to a filled @ref hs_expr_ext_t structure that defines
diff -pruN 5.4.0-2/src/hs_internal.h 5.4.2-1/src/hs_internal.h
--- 5.4.0-2/src/hs_internal.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/hs_internal.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Intel Corporation
+ * Copyright (c) 2019-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -80,7 +80,9 @@ extern "C"
                     | HS_FLAG_PREFILTER \
                     | HS_FLAG_SINGLEMATCH \
                     | HS_FLAG_ALLOWEMPTY \
-                    | HS_FLAG_SOM_LEFTMOST)
+                    | HS_FLAG_SOM_LEFTMOST \
+                    | HS_FLAG_COMBINATION \
+                    | HS_FLAG_QUIET)
 
 #ifdef __cplusplus
 } /* extern "C" */
diff -pruN 5.4.0-2/src/hwlm/noodle_engine_sse.c 5.4.2-1/src/hwlm/noodle_engine_sse.c
--- 5.4.0-2/src/hwlm/noodle_engine_sse.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/hwlm/noodle_engine_sse.c	2023-04-19 09:34:39.000000000 +0000
@@ -106,7 +106,7 @@ hwlm_error_t scanDoubleShort(const struc
     if (!l) {
         return HWLM_SUCCESS;
     }
-    assert(l <= 32);
+    assert(l <= 16);
 
     DEBUG_PRINTF("d %zu\n", d - buf);
     m128 v = zeroes128();
diff -pruN 5.4.0-2/src/nfa/goughcompile.cpp 5.4.2-1/src/nfa/goughcompile.cpp
--- 5.4.0-2/src/nfa/goughcompile.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/nfa/goughcompile.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -207,6 +207,10 @@ void makeCFG_top_edge(GoughGraph &cfg, c
             assert(contains(src_slots, slot_id));
 
             shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
+            if (!vmin) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             cfg[e].vars.push_back(vmin);
             final_var = vmin.get();
 
@@ -318,6 +322,10 @@ void makeCFG_edge(GoughGraph &cfg, const
             DEBUG_PRINTF("bypassing min on join %u\n", slot_id);
         } else {
             shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
+            if (!vmin) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             cfg[e].vars.push_back(vmin);
             final_var = vmin.get();
 
diff -pruN 5.4.0-2/src/nfa/mcclellancompile.cpp 5.4.2-1/src/nfa/mcclellancompile.cpp
--- 5.4.0-2/src/nfa/mcclellancompile.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/nfa/mcclellancompile.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -1082,7 +1082,9 @@ void find_better_daddy(dfa_info &info, d
         // Use the daddy already set for this state so long as it isn't already
         // a Sherman state.
         dstate_id_t daddy = currState.daddy;
-        if (!info.is_sherman(daddy) && !info.is_widestate(daddy)) {
+        if (info.is_widestate(daddy)) {
+            return;
+        } else if (!info.is_sherman(daddy)) {
             hinted.insert(currState.daddy);
         } else {
             // Fall back to granddaddy, which has already been processed (due
diff -pruN 5.4.0-2/src/nfa/repeatcompile.cpp 5.4.2-1/src/nfa/repeatcompile.cpp
--- 5.4.0-2/src/nfa/repeatcompile.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/nfa/repeatcompile.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -124,6 +124,10 @@ RepeatStateInfo::RepeatStateInfo(enum Re
                                  const depth &repeatMax, u32 minPeriod)
     : stateSize(0), packedCtrlSize(0), horizon(0), patchCount(0),
       patchSize(0), encodingSize(0), patchesOffset(0) {
+    if (type == REPEAT_SPARSE_OPTIMAL_P && minPeriod == 0) {
+        assert(0);
+        throw std::domain_error("SPARSE_OPTIMAL_P must have non-zero minPeriod.");
+    }
     assert(repeatMin <= repeatMax);
     assert(repeatMax.is_reachable());
     assert(minPeriod || type != REPEAT_SPARSE_OPTIMAL_P);
diff -pruN 5.4.0-2/src/nfagraph/ng_som.cpp 5.4.2-1/src/nfagraph/ng_som.cpp
--- 5.4.0-2/src/nfagraph/ng_som.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/nfagraph/ng_som.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -2446,6 +2446,10 @@ static
 bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) {
     ue2_literal lit;
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
+    if (!rhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
     if (!ng.cc.grey.allowLitHaig) {
         return false;
     }
@@ -2510,6 +2514,11 @@ bool doHaigLitHaigSom(NG &ng, NGHolder &
     ue2_literal lit;
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
+    if (!rhs || !lhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
+
     if (!splitOffBestLiteral(g, regions, &lit, &*lhs, &*rhs, ng.cc)) {
         return false;
     }
diff -pruN 5.4.0-2/src/nfagraph/ng_violet.cpp 5.4.2-1/src/nfagraph/ng_violet.cpp
--- 5.4.0-2/src/nfagraph/ng_violet.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/nfagraph/ng_violet.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1036,6 +1036,11 @@ bool splitRoseEdge(const NGHolder &base_
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
     shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
 
+    if (!lhs || !rhs) {
+        assert(0);
+        throw std::bad_alloc();
+    }
+
     unordered_map<NFAVertex, NFAVertex> lhs_map;
     unordered_map<NFAVertex, NFAVertex> rhs_map;
 
@@ -1229,6 +1234,10 @@ void splitEdgesByCut(NGHolder &h, RoseIn
             DEBUG_PRINTF("splitting on pivot %zu\n", h[pivot].index);
             unordered_map<NFAVertex, NFAVertex> temp_map;
             shared_ptr<NGHolder> new_lhs = make_shared<NGHolder>();
+            if (!new_lhs) {
+                assert(0);
+                throw std::bad_alloc();
+            }
             splitLHS(h, pivot, new_lhs.get(), &temp_map);
 
             /* want to cut off paths to pivot from things other than the pivot -
@@ -1310,6 +1319,10 @@ void splitEdgesByCut(NGHolder &h, RoseIn
             if (!contains(done_rhs, adj)) {
                 unordered_map<NFAVertex, NFAVertex> temp_map;
                 shared_ptr<NGHolder> new_rhs = make_shared<NGHolder>();
+                if (!new_rhs) {
+                    assert(0);
+                    throw std::bad_alloc();
+                }
                 splitRHS(h, adj, new_rhs.get(), &temp_map);
                 remove_edge(new_rhs->start, new_rhs->accept, *new_rhs);
                 remove_edge(new_rhs->start, new_rhs->acceptEod, *new_rhs);
@@ -2281,6 +2294,10 @@ void splitEdgesForSuffix(const NGHolder
     assert(!splitters.empty());
 
     shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
+    if (!lhs) {
+        assert(0);
+        throw bad_alloc();
+    }
     unordered_map<NFAVertex, NFAVertex> v_map;
     cloneHolder(*lhs, base_graph, &v_map);
     lhs->kind = NFA_INFIX;
diff -pruN 5.4.0-2/src/parser/logical_combination.cpp 5.4.2-1/src/parser/logical_combination.cpp
--- 5.4.0-2/src/parser/logical_combination.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/parser/logical_combination.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -140,7 +140,8 @@ void ParsedLogical::validateSubIDs(const
         }
         hs_compile_error_t *compile_err = NULL;
         hs_expr_info_t *info = NULL;
-        hs_error_t err = hs_expression_info(expressions[i], flags[i], &info,
+        hs_error_t err = hs_expression_info(expressions[i],
+                                            flags ? flags[i] : 0, &info,
                                             &compile_err);
         if (err != HS_SUCCESS) {
             hs_free_compile_error(compile_err);
diff -pruN 5.4.0-2/src/parser/utf8_validate.cpp 5.4.2-1/src/parser/utf8_validate.cpp
--- 5.4.0-2/src/parser/utf8_validate.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/parser/utf8_validate.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2022, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -72,7 +72,7 @@ bool isValidUtf8(const char *expression,
     while (i < len) {
         DEBUG_PRINTF("byte %zu: 0x%02x\n", i, s[i]);
         // One octet.
-        if (s[i] < 0x7f) {
+        if (s[i] <= 0x7f) {
             DEBUG_PRINTF("one octet\n");
             i++;
             continue;
diff -pruN 5.4.0-2/src/rose/program_runtime.c 5.4.2-1/src/rose/program_runtime.c
--- 5.4.0-2/src/rose/program_runtime.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/rose/program_runtime.c	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -3110,6 +3110,7 @@ hwlmcb_rv_t roseRunProgram_l(const struc
 
     const char in_catchup = prog_flags & ROSE_PROG_FLAG_IN_CATCHUP;
     const char from_mpv = prog_flags & ROSE_PROG_FLAG_FROM_MPV;
+    const char skip_mpv_catchup = prog_flags & ROSE_PROG_FLAG_SKIP_MPV_CATCHUP;
 
     const char *pc_base = getByOffset(t, programOffset);
     const char *pc = pc_base;
@@ -3206,6 +3207,17 @@ hwlmcb_rv_t roseRunProgram_l(const struc
             }
             L_PROGRAM_NEXT_INSTRUCTION
 
+            L_PROGRAM_CASE(CATCH_UP_MPV) {
+                if (from_mpv || skip_mpv_catchup) {
+                    DEBUG_PRINTF("skipping mpv catchup\n");
+                } else if (roseCatchUpMPV(t,
+                                          end - scratch->core_info.buf_offset,
+                                          scratch) == HWLM_TERMINATE_MATCHING) {
+                    return HWLM_TERMINATE_MATCHING;
+                }
+            }
+            L_PROGRAM_NEXT_INSTRUCTION
+
             L_PROGRAM_CASE(SOM_FROM_REPORT) {
                 som = handleSomExternal(scratch, &ri->som, end);
                 DEBUG_PRINTF("som from report %u is %llu\n", ri->som.onmatch,
@@ -3213,6 +3225,15 @@ hwlmcb_rv_t roseRunProgram_l(const struc
             }
             L_PROGRAM_NEXT_INSTRUCTION
 
+            L_PROGRAM_CASE(TRIGGER_SUFFIX) {
+                if (roseTriggerSuffix(t, scratch, ri->queue, ri->event, som,
+                                      end) == HWLM_TERMINATE_MATCHING) {
+                    return HWLM_TERMINATE_MATCHING;
+                }
+                work_done = 1;
+            }
+            L_PROGRAM_NEXT_INSTRUCTION
+
             L_PROGRAM_CASE(DEDUPE) {
                 updateSeqPoint(tctxt, end, from_mpv);
                 const char do_som = t->hasSom; // TODO: constant propagate
diff -pruN 5.4.0-2/src/rose/rose_build_convert.cpp 5.4.2-1/src/rose/rose_build_convert.cpp
--- 5.4.0-2/src/rose/rose_build_convert.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/rose/rose_build_convert.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -562,6 +562,10 @@ bool handleMixedPrefixCliche(const NGHol
     DEBUG_PRINTF("woot?\n");
 
     shared_ptr<NGHolder> h_new = make_shared<NGHolder>();
+    if (!h_new) {
+        assert(0);
+        throw std::bad_alloc();
+    }
     unordered_map<NFAVertex, NFAVertex> rhs_map;
     vector<NFAVertex> exits_vec;
     insert(&exits_vec, exits_vec.end(), exits);
diff -pruN 5.4.0-2/src/runtime.c 5.4.2-1/src/runtime.c
--- 5.4.0-2/src/runtime.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/runtime.c	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2022, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -1013,6 +1013,7 @@ hs_error_t HS_CDECL hs_close_stream(hs_s
         report_eod_matches(id, scratch, onEvent, context);
         if (unlikely(internal_matching_error(scratch))) {
             unmarkScratchInUse(scratch);
+            hs_stream_free(id);
             return HS_UNKNOWN_ERROR;
         }
         unmarkScratchInUse(scratch);
diff -pruN 5.4.0-2/src/scratch.c 5.4.2-1/src/scratch.c
--- 5.4.0-2/src/scratch.c	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/scratch.c	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2023, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
diff -pruN 5.4.0-2/src/scratch.h 5.4.2-1/src/scratch.h
--- 5.4.0-2/src/scratch.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/scratch.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2023, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
diff -pruN 5.4.0-2/src/smallwrite/smallwrite_build.cpp 5.4.2-1/src/smallwrite/smallwrite_build.cpp
--- 5.4.0-2/src/smallwrite/smallwrite_build.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/smallwrite/smallwrite_build.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -78,7 +78,7 @@ namespace ue2 {
 struct LitTrieVertexProps {
     LitTrieVertexProps() = default;
     explicit LitTrieVertexProps(u8 c_in) : c(c_in) {}
-    size_t index; // managed by ue2_graph
+    size_t index = 0; // managed by ue2_graph
     u8 c = 0; //!< character reached on this vertex
     flat_set<ReportID> reports; //!< managed reports fired on this vertex
 };
diff -pruN 5.4.0-2/src/state.h 5.4.2-1/src/state.h
--- 5.4.0-2/src/state.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/state.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2023, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
diff -pruN 5.4.0-2/src/stream_compress_impl.h 5.4.2-1/src/stream_compress_impl.h
--- 5.4.0-2/src/stream_compress_impl.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/stream_compress_impl.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, Intel Corporation
+ * Copyright (c) 2017-2023, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
diff -pruN 5.4.0-2/src/util/alloc.h 5.4.2-1/src/util/alloc.h
--- 5.4.0-2/src/util/alloc.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/util/alloc.h	2023-04-19 09:34:39.000000000 +0000
@@ -76,7 +76,11 @@ public:
 
     T *allocate(std::size_t size) const {
         size_t alloc_size = size * sizeof(T);
-        return static_cast<T *>(aligned_malloc_internal(alloc_size, N));
+        T *ptr = static_cast<T *>(aligned_malloc_internal(alloc_size, N));
+        if (!ptr) {
+            throw std::bad_alloc();
+        }
+        return ptr;
     }
 
     void deallocate(T *x, std::size_t) const noexcept {
diff -pruN 5.4.0-2/src/util/graph_undirected.h 5.4.2-1/src/util/graph_undirected.h
--- 5.4.0-2/src/util/graph_undirected.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/util/graph_undirected.h	2023-04-19 09:34:39.000000000 +0000
@@ -70,8 +70,8 @@ class undirected_graph_edge_descriptor
     using base_vertex_type = typename base_graph_traits::vertex_descriptor;
 
     base_edge_type underlying_edge;
-    const base_graph_type *g;
-    bool reverse; // if true, reverse vertices in source() and target()
+    const base_graph_type *g = nullptr;
+    bool reverse = false; // if true, reverse vertices in source() and target()
 
     inline std::pair<base_vertex_type, base_vertex_type>
     canonical_edge() const {
diff -pruN 5.4.0-2/src/util/simd_utils.h 5.4.2-1/src/util/simd_utils.h
--- 5.4.0-2/src/util/simd_utils.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/util/simd_utils.h	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -156,6 +156,16 @@ static really_inline u32 movd(const m128
     return _mm_cvtsi128_si32(in);
 }
 
+static really_inline u64a movq(const m128 in) {
+#if defined(ARCH_X86_64)
+    return _mm_cvtsi128_si64(in);
+#else // 32-bit - this is horrific
+    u32 lo = movd(in);
+    u32 hi = movd(_mm_srli_epi64(in, 32));
+    return (u64a)hi << 32 | lo;
+#endif
+}
+
 #if defined(HAVE_AVX512)
 static really_inline u32 movd512(const m512 in) {
     // NOTE: seems gcc doesn't support _mm512_cvtsi512_si32(in),
@@ -166,20 +176,10 @@ static really_inline u32 movd512(const m
 static really_inline u64a movq512(const m512 in) {
     // NOTE: seems AVX512 doesn't support _mm512_cvtsi512_si64(in),
     //       so we use 2-step convertions to work around.
-    return _mm_cvtsi128_si64(_mm512_castsi512_si128(in));
+    return movq(_mm512_castsi512_si128(in));
 }
 #endif
 
-static really_inline u64a movq(const m128 in) {
-#if defined(ARCH_X86_64)
-    return _mm_cvtsi128_si64(in);
-#else // 32-bit - this is horrific
-    u32 lo = movd(in);
-    u32 hi = movd(_mm_srli_epi64(in, 32));
-    return (u64a)hi << 32 | lo;
-#endif
-}
-
 /* another form of movq */
 static really_inline
 m128 load_m128_from_u64a(const u64a *p) {
@@ -791,7 +791,7 @@ m128 movdq_lo(m256 x) {
 #define lshift128_m256(a, count_immed) _mm256_slli_si256(a, count_immed)
 #define extract64from256(a, imm) _mm_extract_epi64(_mm256_extracti128_si256(a, imm >> 1), imm % 2)
 #define extract32from256(a, imm) _mm_extract_epi32(_mm256_extracti128_si256(a, imm >> 2), imm % 4)
-#define extractlow64from256(a) _mm_cvtsi128_si64(cast256to128(a))
+#define extractlow64from256(a) movq(cast256to128(a))
 #define extractlow32from256(a) movd(cast256to128(a))
 #define interleave256hi(a, b) _mm256_unpackhi_epi8(a, b)
 #define interleave256lo(a, b) _mm256_unpacklo_epi8(a, b)
diff -pruN 5.4.0-2/src/util/ue2string.h 5.4.2-1/src/util/ue2string.h
--- 5.4.0-2/src/util/ue2string.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/src/util/ue2string.h	2023-04-19 09:34:39.000000000 +0000
@@ -133,7 +133,7 @@ public:
             : lit(&lit_in), idx(idx_in) {}
 
         const ue2_literal *lit = nullptr;
-        size_t idx;
+        size_t idx = 0;
     };
 
     using const_reverse_iterator = std::reverse_iterator<const_iterator>;
diff -pruN 5.4.0-2/tools/hsbench/data_corpus.cpp 5.4.2-1/tools/hsbench/data_corpus.cpp
--- 5.4.0-2/tools/hsbench/data_corpus.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hsbench/data_corpus.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -58,7 +58,10 @@ void readRow(sqlite3_stmt *statement, ve
     }
     auto internal_stream_index = stream_indices[stream_id];
 
-    assert(blob || bytes > 0);
+    if (!(blob &&  bytes > 0)) {
+        assert(0);
+        throw std::domain_error("Invalid blob or bytes from sqlite3.");
+    }
     blocks.emplace_back(id, stream_id, internal_stream_index,
                         string(blob, blob + bytes));
 }
diff -pruN 5.4.0-2/tools/hsbench/main.cpp 5.4.2-1/tools/hsbench/main.cpp
--- 5.4.0-2/tools/hsbench/main.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hsbench/main.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -760,6 +760,11 @@ u64a byte_size(const vector<DataBlock> &
         total += block.payload.size();
     }
 
+    if (total == 0) {
+        assert(0);
+        throw std::invalid_argument("Empty corpus.");
+    }
+
     return total;
 }
 
diff -pruN 5.4.0-2/tools/hscollider/DatabaseProxy.h 5.4.2-1/tools/hscollider/DatabaseProxy.h
--- 5.4.0-2/tools/hscollider/DatabaseProxy.h	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hscollider/DatabaseProxy.h	2023-04-19 09:34:39.000000000 +0000
@@ -61,7 +61,7 @@ public:
         std::lock_guard<std::mutex> lock(mutex);
         if (failed) {
             // We have previously failed to compile this database.
-            return nullptr;
+            throw CompileFailed("Unable to compile db previously.");
         }
         if (db) {
             return db;
diff -pruN 5.4.0-2/tools/hscollider/NfaGeneratedCorpora.cpp 5.4.2-1/tools/hscollider/NfaGeneratedCorpora.cpp
--- 5.4.0-2/tools/hscollider/NfaGeneratedCorpora.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hscollider/NfaGeneratedCorpora.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -101,7 +101,7 @@ void NfaGeneratedCorpora::generate(unsig
         pl.logicalKeyRenumber();
         const auto &m_lkey = pl.getLkeyMap();
         assert(!m_lkey.empty());
-        u32 a_subid; // arbitrary sub id
+        u32 a_subid = 0; // arbitrary sub id
         unordered_map<u32, vector<Corpus>> m_data;
         for (const auto &it : m_lkey) {
             a_subid = it.first;
diff -pruN 5.4.0-2/tools/hscollider/Thread.cpp 5.4.2-1/tools/hscollider/Thread.cpp
--- 5.4.0-2/tools/hscollider/Thread.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hscollider/Thread.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -98,6 +98,6 @@ void *Thread::runThread(void *thr) {
 }
 
 
-Thread::Thread(size_t num) : thread_id(num) {}
+Thread::Thread(size_t num) : thread_id(num), thread() {}
 
 Thread::~Thread() {}
diff -pruN 5.4.0-2/tools/hscollider/args.cpp 5.4.2-1/tools/hscollider/args.cpp
--- 5.4.0-2/tools/hscollider/args.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hscollider/args.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -503,8 +503,8 @@ void processArgs(int argc, char *argv[],
                 } else if (in_corpora) {
                     corpora->push_back(optarg);
                     in_corpora = 2;
-                    break;
                 }
+                break;
             case 0:
                 break;
             default:
diff -pruN 5.4.0-2/tools/hscollider/sig.cpp 5.4.2-1/tools/hscollider/sig.cpp
--- 5.4.0-2/tools/hscollider/sig.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/tools/hscollider/sig.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -38,6 +38,7 @@
 
 #if defined(HAVE_SIGACTION) || defined(_WIN32)
 #include <signal.h>
+#define STACK_SIZE 8192 // linux kernel default stack size for x86
 #endif
 
 #ifdef HAVE_BACKTRACE
@@ -175,7 +176,7 @@ void installSignalHandler(void) {
 }
 
 #ifdef HAVE_SIGALTSTACK
-static TLS_VARIABLE char alt_stack_loc[SIGSTKSZ];
+static TLS_VARIABLE char alt_stack_loc[STACK_SIZE];
 #endif
 
 void setSignalStack(void) {
@@ -187,7 +188,7 @@ void setSignalStack(void) {
     stack_t alt_stack;
     memset(&alt_stack, 0, sizeof(alt_stack));
     alt_stack.ss_flags = 0;
-    alt_stack.ss_size = SIGSTKSZ;
+    alt_stack.ss_size = STACK_SIZE;
     alt_stack.ss_sp = alt_stack_loc;
     if (!sigaltstack(&alt_stack, nullptr)) {
         act.sa_flags |= SA_ONSTACK;
diff -pruN 5.4.0-2/unit/hyperscan/single.cpp 5.4.2-1/unit/hyperscan/single.cpp
--- 5.4.0-2/unit/hyperscan/single.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/unit/hyperscan/single.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -363,8 +363,9 @@ static const unsigned validModes[] = {
 // Mode bits for switching off various architecture features
 static const unsigned long long featureMask[] = {
     ~0ULL, /* native */
-    ~(HS_CPU_FEATURES_AVX2 | HS_CPU_FEATURES_AVX512), /* no avx2 */
-    ~HS_CPU_FEATURES_AVX512, /* no avx512 */
+    ~(HS_CPU_FEATURES_AVX2 | HS_CPU_FEATURES_AVX512 | HS_CPU_FEATURES_AVX512VBMI), /* no avx2 */
+    ~(HS_CPU_FEATURES_AVX512 | HS_CPU_FEATURES_AVX512VBMI), /* no avx512 */
+    ~HS_CPU_FEATURES_AVX512VBMI, /* no avx512vbmi */
 };
 
 INSTANTIATE_TEST_CASE_P(Single,
diff -pruN 5.4.0-2/unit/internal/database.cpp 5.4.2-1/unit/internal/database.cpp
--- 5.4.0-2/unit/internal/database.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/unit/internal/database.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2015-2021, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -56,6 +56,10 @@ TEST(DB, flagsToPlatform) {
     p.cpu_features |= HS_CPU_FEATURES_AVX512;
 #endif
 
+#if defined(HAVE_AVX512VBMI)
+    p.cpu_features |= HS_CPU_FEATURES_AVX512VBMI;
+#endif
+
     platform_t pp = target_to_platform(target_t(p));
     ASSERT_EQ(pp, hs_current_platform);
 }
diff -pruN 5.4.0-2/unit/internal/utf8_validate.cpp 5.4.2-1/unit/internal/utf8_validate.cpp
--- 5.4.0-2/unit/internal/utf8_validate.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/unit/internal/utf8_validate.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, Intel Corporation
+ * Copyright (c) 2015-2022, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -64,8 +64,8 @@ static ValidUtf8TestInfo valid_utf8_test
     {"공동경비구역", true},
     {"জলসাঘর", true},
 
-    // Invalid one-byte caseS.
-    {"\x7f", false},
+    // Valid one-byte caseS.
+    {"\x7f", true}, // \x7f is valid
 
     // These bytes should never appear in a UTF-8 stream.
     {"\xc0", false},
diff -pruN 5.4.0-2/util/ng_corpus_editor.cpp 5.4.2-1/util/ng_corpus_editor.cpp
--- 5.4.0-2/util/ng_corpus_editor.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/util/ng_corpus_editor.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -268,12 +268,12 @@ void CorpusEditorUtf8::flip_case(vector<
 unichar CorpusEditorUtf8::chooseCodePoint(void) {
     /* We need to ensure that we don't pick a surrogate cp */
     const u32 range =
-        MAX_UNICODE + 1 - (UNICODE_SURROGATE_MAX + UNICODE_SURROGATE_MIN + 1);
+        MAX_UNICODE + 1 - (UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1);
     unichar raw = props.rand(0, range - 1);
     if (raw < UNICODE_SURROGATE_MIN) {
         return raw;
     } else {
-        return raw + UNICODE_SURROGATE_MAX + 1;
+        return raw + UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1;
     }
 }
 
diff -pruN 5.4.0-2/util/ng_corpus_generator.cpp 5.4.2-1/util/ng_corpus_generator.cpp
--- 5.4.0-2/util/ng_corpus_generator.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/util/ng_corpus_generator.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -477,14 +477,14 @@ void CorpusGeneratorUtf8::generateCorpus
  * that we've been asked for. */
 unichar CorpusGeneratorUtf8::getRandomChar() {
     u32 range = MAX_UNICODE + 1
-                - (UNICODE_SURROGATE_MAX + UNICODE_SURROGATE_MIN + 1);
+                - (UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1);
     range = min(cProps.alphabetSize, range);
     assert(range);
 
     unichar c = 'a' + cProps.rand(0, range - 1);
 
     if (c >= UNICODE_SURROGATE_MIN) {
-        c =+ UNICODE_SURROGATE_MAX + 1;
+        c += UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1;
     }
 
     return c % (MAX_UNICODE + 1);
diff -pruN 5.4.0-2/util/ng_corpus_properties.cpp 5.4.2-1/util/ng_corpus_properties.cpp
--- 5.4.0-2/util/ng_corpus_properties.cpp	2021-01-13 14:39:34.000000000 +0000
+++ 5.4.2-1/util/ng_corpus_properties.cpp	2023-04-19 09:34:39.000000000 +0000
@@ -42,7 +42,7 @@ CorpusProperties::CorpusProperties()
     : matchness(100), unmatchness(0), randomness(0), prefixRange(0, 0),
       suffixRange(0, 0), cycleMin(1), cycleMax(1),
       corpusLimit(DEFAULT_CORPUS_GENERATOR_LIMIT), editDistance(0),
-      alphabetSize(~0) {
+      alphabetSize(~0), rngSeed(0) {
     // empty
 }
 
