@@ -151,7 +151,7 @@ void populateCoreInfo(struct hs_scratch *s, const struct RoseEngine *rose,
151151}
152152
153153#define STATUS_VALID_BITS \
154- (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_DELAY_DIRTY)
154+ (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_DELAY_DIRTY | STATUS_ERROR )
155155
156156/** \brief Retrieve status bitmask from stream state. */
157157static really_inline
@@ -428,7 +428,10 @@ hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
428428 }
429429
430430done_scan :
431- if (told_to_stop_matching (scratch )) {
431+ if (unlikely (internal_matching_error (scratch ))) {
432+ unmarkScratchInUse (scratch );
433+ return HS_UNKNOWN_ERROR ;
434+ } else if (told_to_stop_matching (scratch )) {
432435 unmarkScratchInUse (scratch );
433436 return HS_SCAN_TERMINATED ;
434437 }
@@ -447,8 +450,17 @@ hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
447450 }
448451
449452set_retval :
453+ if (unlikely (internal_matching_error (scratch ))) {
454+ unmarkScratchInUse (scratch );
455+ return HS_UNKNOWN_ERROR ;
456+ }
457+
450458 if (rose -> flushCombProgramOffset ) {
451459 if (roseRunFlushCombProgram (rose , scratch , ~0ULL ) == MO_HALT_MATCHING ) {
460+ if (unlikely (internal_matching_error (scratch ))) {
461+ unmarkScratchInUse (scratch );
462+ return HS_UNKNOWN_ERROR ;
463+ }
452464 unmarkScratchInUse (scratch );
453465 return HS_SCAN_TERMINATED ;
454466 }
@@ -626,7 +638,7 @@ void report_eod_matches(hs_stream_t *id, hs_scratch_t *scratch,
626638 char * state = getMultiState (id );
627639 u8 status = getStreamStatus (state );
628640
629- if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED )) {
641+ if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_ERROR )) {
630642 DEBUG_PRINTF ("stream is broken, just freeing storage\n" );
631643 return ;
632644 }
@@ -748,6 +760,10 @@ hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
748760 return HS_SCRATCH_IN_USE ;
749761 }
750762 report_eod_matches (to_id , scratch , onEvent , context );
763+ if (unlikely (internal_matching_error (scratch ))) {
764+ unmarkScratchInUse (scratch );
765+ return HS_UNKNOWN_ERROR ;
766+ }
751767 unmarkScratchInUse (scratch );
752768 }
753769
@@ -863,9 +879,11 @@ hs_error_t hs_scan_stream_internal(hs_stream_t *id, const char *data,
863879 char * state = getMultiState (id );
864880
865881 u8 status = getStreamStatus (state );
866- if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED )) {
882+ if (status & (STATUS_TERMINATED | STATUS_EXHAUSTED | STATUS_ERROR )) {
867883 DEBUG_PRINTF ("stream is broken, halting scan\n" );
868- if (status & STATUS_TERMINATED ) {
884+ if (status & STATUS_ERROR ) {
885+ return HS_UNKNOWN_ERROR ;
886+ } else if (status & STATUS_TERMINATED ) {
869887 return HS_SCAN_TERMINATED ;
870888 } else {
871889 return HS_SUCCESS ;
@@ -937,7 +955,9 @@ hs_error_t hs_scan_stream_internal(hs_stream_t *id, const char *data,
937955
938956 setStreamStatus (state , scratch -> core_info .status );
939957
940- if (likely (!can_stop_matching (scratch ))) {
958+ if (unlikely (internal_matching_error (scratch ))) {
959+ return HS_UNKNOWN_ERROR ;
960+ } else if (likely (!can_stop_matching (scratch ))) {
941961 maintainHistoryBuffer (rose , state , data , length );
942962 id -> offset += length ; /* maintain offset */
943963
@@ -986,13 +1006,22 @@ hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
9861006 return HS_SCRATCH_IN_USE ;
9871007 }
9881008 report_eod_matches (id , scratch , onEvent , context );
1009+ if (unlikely (internal_matching_error (scratch ))) {
1010+ unmarkScratchInUse (scratch );
1011+ return HS_UNKNOWN_ERROR ;
1012+ }
9891013 unmarkScratchInUse (scratch );
9901014 }
9911015
9921016 if (id -> rose -> flushCombProgramOffset && !told_to_stop_matching (scratch )) {
9931017 if (roseRunFlushCombProgram (id -> rose , scratch , ~0ULL )
9941018 == MO_HALT_MATCHING ) {
9951019 scratch -> core_info .status |= STATUS_TERMINATED ;
1020+ if (unlikely (internal_matching_error (scratch ))) {
1021+ unmarkScratchInUse (scratch );
1022+ return HS_UNKNOWN_ERROR ;
1023+ }
1024+ unmarkScratchInUse (scratch );
9961025 }
9971026 }
9981027
@@ -1018,13 +1047,22 @@ hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
10181047 return HS_SCRATCH_IN_USE ;
10191048 }
10201049 report_eod_matches (id , scratch , onEvent , context );
1050+ if (unlikely (internal_matching_error (scratch ))) {
1051+ unmarkScratchInUse (scratch );
1052+ return HS_UNKNOWN_ERROR ;
1053+ }
10211054 unmarkScratchInUse (scratch );
10221055 }
10231056
10241057 if (id -> rose -> flushCombProgramOffset && !told_to_stop_matching (scratch )) {
10251058 if (roseRunFlushCombProgram (id -> rose , scratch , ~0ULL )
10261059 == MO_HALT_MATCHING ) {
10271060 scratch -> core_info .status |= STATUS_TERMINATED ;
1061+ if (unlikely (internal_matching_error (scratch ))) {
1062+ unmarkScratchInUse (scratch );
1063+ return HS_UNKNOWN_ERROR ;
1064+ }
1065+ unmarkScratchInUse (scratch );
10281066 }
10291067 }
10301068
@@ -1139,7 +1177,10 @@ hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
11391177 if (onEvent ) {
11401178 report_eod_matches (id , scratch , onEvent , context );
11411179
1142- if (told_to_stop_matching (scratch )) {
1180+ if (unlikely (internal_matching_error (scratch ))) {
1181+ unmarkScratchInUse (scratch );
1182+ return HS_UNKNOWN_ERROR ;
1183+ } else if (told_to_stop_matching (scratch )) {
11431184 unmarkScratchInUse (scratch );
11441185 return HS_SCAN_TERMINATED ;
11451186 }
@@ -1237,6 +1278,10 @@ hs_error_t HS_CDECL hs_reset_and_expand_stream(hs_stream_t *to_stream,
12371278 return HS_SCRATCH_IN_USE ;
12381279 }
12391280 report_eod_matches (to_stream , scratch , onEvent , context );
1281+ if (unlikely (internal_matching_error (scratch ))) {
1282+ unmarkScratchInUse (scratch );
1283+ return HS_UNKNOWN_ERROR ;
1284+ }
12401285 unmarkScratchInUse (scratch );
12411286 }
12421287
0 commit comments