Skip to content

Commit bc3b191

Browse files
committed
Merge branch 'github_develop' into github_master
2 parents c37166d + 6473173 commit bc3b191

File tree

9 files changed

+35
-30
lines changed

9 files changed

+35
-30
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This is a list of notable changes to Hyperscan, in reverse chronological order.
44

5+
## [5.4.2] 2023-04-19
6+
- Roll back bugfix for github issue #350: Besides using scratch for
7+
corresponding database, Hyperscan also allows user to use larger scratch
8+
allocated for another database. Users can leverage this property to achieve
9+
safe scratch usage in multi-database scenarios. Behaviors beyond these are
10+
discouraged and results are undefined.
11+
- Fix hsdump issue due to invalid nfa type.
12+
513
## [5.4.1] 2023-02-20
614
- The Intel Hyperscan team is pleased to provide a bug fix release to our open source library.
715
Intel also maintains an upgraded version available through your Intel sales representative.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project (hyperscan C CXX)
33

44
set (HS_MAJOR_VERSION 5)
55
set (HS_MINOR_VERSION 4)
6-
set (HS_PATCH_VERSION 1)
6+
set (HS_PATCH_VERSION 2)
77
set (HS_VERSION ${HS_MAJOR_VERSION}.${HS_MINOR_VERSION}.${HS_PATCH_VERSION})
88

99
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

src/hs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#define HS_MAJOR 5
4545
#define HS_MINOR 4
46-
#define HS_PATCH 1
46+
#define HS_PATCH 2
4747

4848
#include "hs_compile.h"
4949
#include "hs_runtime.h"

src/nfa/nfa_dump_dispatch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ namespace ue2 {
7575
DISPATCH_CASE(LBR_NFA_VERM, LbrVerm, dbnt_func); \
7676
DISPATCH_CASE(LBR_NFA_NVERM, LbrNVerm, dbnt_func); \
7777
DISPATCH_CASE(LBR_NFA_SHUF, LbrShuf, dbnt_func); \
78-
DISPATCH_CASE(LBR_NFA_VSHUF, LbrVShuf, dbnt_func); \
7978
DISPATCH_CASE(LBR_NFA_TRUF, LbrTruf, dbnt_func); \
8079
DISPATCH_CASE(CASTLE_NFA, Castle, dbnt_func); \
8180
DISPATCH_CASE(SHENG_NFA, Sheng, dbnt_func); \

src/runtime.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ u8 *getHistory(char *state, const struct RoseEngine *t, u64a offset) {
9090
* callers.
9191
*/
9292
static 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

504510
static really_inline
505511
void 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))) {

src/scratch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2022, Intel Corporation
2+
* Copyright (c) 2015-2023, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -373,15 +373,13 @@ hs_error_t HS_CDECL hs_alloc_scratch(const hs_database_t *db,
373373
hs_scratch_free((*scratch)->scratch_alloc);
374374
}
375375

376-
proto->db_crc = db->crc32;
377376
hs_error_t alloc_ret = alloc_scratch(proto, scratch);
378377
hs_scratch_free(proto_tmp); /* kill off temp used for sizing */
379378
if (alloc_ret != HS_SUCCESS) {
380379
*scratch = NULL;
381380
return alloc_ret;
382381
}
383382
} else {
384-
(*scratch)->db_crc = db->crc32;
385383
hs_scratch_free(proto_tmp); /* kill off temp used for sizing */
386384
unmarkScratchInUse(*scratch);
387385
}

src/scratch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2022, Intel Corporation
2+
* Copyright (c) 2015-2023, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -171,7 +171,6 @@ struct match_deduper {
171171
*/
172172
struct ALIGN_CL_DIRECTIVE hs_scratch {
173173
u32 magic;
174-
u32 db_crc; /**< identity of a scratch space, for validity check */
175174
u8 in_use; /**< non-zero when being used by an API call. */
176175
u32 queueCount;
177176
u32 activeQueueArraySize; /**< size of active queue array fatbit in bytes */

src/state.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2022, Intel Corporation
2+
* Copyright (c) 2015-2023, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -57,9 +57,6 @@ struct hs_stream {
5757

5858
/** \brief The current stream offset. */
5959
u64a offset;
60-
61-
/** \brief Identity of hs_stream, for scratch validity check. */
62-
u32 crc32;
6360
};
6461

6562
#define getMultiState(hs_s) ((char *)(hs_s) + sizeof(*(hs_s)))

src/stream_compress_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022, Intel Corporation
2+
* Copyright (c) 2017-2023, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -116,7 +116,6 @@ size_t JOIN(sc_, FN_SUFFIX)(const struct RoseEngine *rose,
116116
= ((STREAM_QUAL char *)stream) + sizeof(struct hs_stream);
117117

118118
COPY_FIELD(stream->offset);
119-
COPY_FIELD(stream->crc32);
120119
ASSIGN(stream->rose, rose);
121120

122121
COPY(stream_body + ROSE_STATE_OFFSET_STATUS_FLAGS, 1);

0 commit comments

Comments
 (0)