@@ -90,7 +90,7 @@ u8 *getHistory(char *state, const struct RoseEngine *t, u64a offset) {
9090 * callers.
9191 */
9292static really_inline
93- char validScratch (const struct hs_scratch * s , u32 crc ) {
93+ char validScratch (const struct RoseEngine * t , const struct hs_scratch * s ) {
9494 if (!ISALIGNED_CL (s )) {
9595 DEBUG_PRINTF ("bad alignment %p\n" , s );
9696 return 0 ;
@@ -101,12 +101,18 @@ char validScratch(const struct hs_scratch *s, u32 crc) {
101101 return 0 ;
102102 }
103103
104- /* add quick rose sanity checks by db crc*/
105- if (s -> db_crc != crc ) {
106- DEBUG_PRINTF ("Improper scratch for current db\n" );
104+ if (t -> mode == HS_MODE_BLOCK && t -> stateOffsets .end > s -> bStateSize ) {
105+ DEBUG_PRINTF ("bad state size\n" );
107106 return 0 ;
108107 }
109108
109+ if (t -> queueCount > s -> queueCount ) {
110+ DEBUG_PRINTF ("bad queue count\n" );
111+ return 0 ;
112+ }
113+
114+ /* TODO: add quick rose sanity checks */
115+
110116 return 1 ;
111117}
112118
@@ -329,7 +335,7 @@ hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
329335 return HS_DB_MODE_ERROR ;
330336 }
331337
332- if (unlikely (!validScratch (scratch , db -> crc32 ))) {
338+ if (unlikely (!validScratch (rose , scratch ))) {
333339 return HS_INVALID ;
334340 }
335341
@@ -503,7 +509,7 @@ void maintainHistoryBuffer(const struct RoseEngine *rose, char *state,
503509
504510static really_inline
505511void init_stream (struct hs_stream * s , const struct RoseEngine * rose ,
506- char init_history , u32 crc ) {
512+ char init_history ) {
507513 char * state = getMultiState (s );
508514
509515 if (init_history ) {
@@ -518,7 +524,6 @@ void init_stream(struct hs_stream *s, const struct RoseEngine *rose,
518524
519525 s -> rose = rose ;
520526 s -> offset = 0 ;
521- s -> crc32 = crc ;
522527
523528 setStreamStatus (state , 0 );
524529 roseInitState (rose , state );
@@ -563,7 +568,7 @@ hs_error_t HS_CDECL hs_open_stream(const hs_database_t *db,
563568 return HS_NOMEM ;
564569 }
565570
566- init_stream (s , rose , 1 , db -> crc32 );
571+ init_stream (s , rose , 1 );
567572
568573 * stream = s ;
569574 return HS_SUCCESS ;
@@ -751,7 +756,7 @@ hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
751756 }
752757
753758 if (onEvent ) {
754- if (!scratch || !validScratch (scratch , to_id -> crc32 )) {
759+ if (!scratch || !validScratch (to_id -> rose , scratch )) {
755760 return HS_INVALID ;
756761 }
757762 if (unlikely (markScratchInUse (scratch ))) {
@@ -977,7 +982,7 @@ hs_error_t HS_CDECL hs_scan_stream(hs_stream_t *id, const char *data,
977982 hs_scratch_t * scratch ,
978983 match_event_handler onEvent , void * context ) {
979984 if (unlikely (!id || !scratch || !data ||
980- !validScratch (scratch , id -> crc32 ))) {
985+ !validScratch (id -> rose , scratch ))) {
981986 return HS_INVALID ;
982987 }
983988
@@ -999,7 +1004,7 @@ hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
9991004 }
10001005
10011006 if (onEvent ) {
1002- if (!scratch || !validScratch (scratch , id -> crc32 )) {
1007+ if (!scratch || !validScratch (id -> rose , scratch )) {
10031008 return HS_INVALID ;
10041009 }
10051010 if (unlikely (markScratchInUse (scratch ))) {
@@ -1029,7 +1034,7 @@ hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
10291034 }
10301035
10311036 if (onEvent ) {
1032- if (!scratch || !validScratch (scratch , id -> crc32 )) {
1037+ if (!scratch || !validScratch (id -> rose , scratch )) {
10331038 return HS_INVALID ;
10341039 }
10351040 if (unlikely (markScratchInUse (scratch ))) {
@@ -1044,7 +1049,7 @@ hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
10441049 }
10451050
10461051 // history already initialised
1047- init_stream (id , id -> rose , 0 , id -> crc32 );
1052+ init_stream (id , id -> rose , 0 );
10481053
10491054 return HS_SUCCESS ;
10501055}
@@ -1123,7 +1128,7 @@ hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
11231128 return HS_DB_MODE_ERROR ;
11241129 }
11251130
1126- if (unlikely (!validScratch (scratch , db -> crc32 ))) {
1131+ if (unlikely (!validScratch (rose , scratch ))) {
11271132 return HS_INVALID ;
11281133 }
11291134
@@ -1133,7 +1138,7 @@ hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
11331138
11341139 hs_stream_t * id = (hs_stream_t * )(scratch -> bstate );
11351140
1136- init_stream (id , rose , 1 , db -> crc32 ); /* open stream */
1141+ init_stream (id , rose , 1 ); /* open stream */
11371142
11381143 for (u32 i = 0 ; i < count ; i ++ ) {
11391144 DEBUG_PRINTF ("block %u/%u offset=%llu len=%u\n" , i , count , id -> offset ,
@@ -1248,7 +1253,7 @@ hs_error_t HS_CDECL hs_reset_and_expand_stream(hs_stream_t *to_stream,
12481253 const struct RoseEngine * rose = to_stream -> rose ;
12491254
12501255 if (onEvent ) {
1251- if (!scratch || !validScratch (scratch , to_stream -> crc32 )) {
1256+ if (!scratch || !validScratch (to_stream -> rose , scratch )) {
12521257 return HS_INVALID ;
12531258 }
12541259 if (unlikely (markScratchInUse (scratch ))) {
0 commit comments