Skip to content

Commit 918b490

Browse files
committed
Fixed out-of-bound memory access issue for large inputs.
1 parent 18c8f5a commit 918b490

File tree

12 files changed

+41
-36
lines changed

12 files changed

+41
-36
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Changes in 2.8.6 (November 18, 2024)
2+
- Fixed out-of-bound memory access issue for large inputs.
3+
14
Changes in 2.8.5 (July 31, 2024)
25
- Miscellaneous changes to reduce compiler warnings about implicit functions.
36

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
project(libsais VERSION 2.8.5 LANGUAGES C DESCRIPTION "libsais is a library for linear time suffix array, longest common prefix array and burrows wheeler transform construction based on induced sorting algorithm.")
3+
project(libsais VERSION 2.8.6 LANGUAGES C DESCRIPTION "libsais is a library for linear time suffix array, longest common prefix array and burrows wheeler transform construction based on induced sorting algorithm.")
44

55
set(CMAKE_C_STANDARD 99)
66
set(CMAKE_C_STANDARD_REQUIRED ON)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The libsais provides simple C99 API to construct suffix array and Burrows-Wheele
2323
The libsais is released under the [Apache License Version 2.0](LICENSE "Apache license")
2424

2525
## Changes
26+
* November 18, 2024 (2.8.6)
27+
* Fixed out-of-bound memory access issue for large inputs.
2628
* July 31, 2024 (2.8.5)
2729
* Miscellaneous changes to reduce compiler warnings about implicit functions.
2830
* June 13, 2024 (2.8.4)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.5
1+
2.8.6

include/libsais.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.
2626

2727
#define LIBSAIS_VERSION_MAJOR 2
2828
#define LIBSAIS_VERSION_MINOR 8
29-
#define LIBSAIS_VERSION_PATCH 5
30-
#define LIBSAIS_VERSION_STRING "2.8.5"
29+
#define LIBSAIS_VERSION_PATCH 6
30+
#define LIBSAIS_VERSION_STRING "2.8.6"
3131

3232
#ifdef _WIN32
3333
#ifdef LIBSAIS_SHARED

include/libsais16.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.
2626

2727
#define LIBSAIS16_VERSION_MAJOR 2
2828
#define LIBSAIS16_VERSION_MINOR 8
29-
#define LIBSAIS16_VERSION_PATCH 5
30-
#define LIBSAIS16_VERSION_STRING "2.8.5"
29+
#define LIBSAIS16_VERSION_PATCH 6
30+
#define LIBSAIS16_VERSION_STRING "2.8.6"
3131

3232
#ifdef _WIN32
3333
#ifdef LIBSAIS_SHARED

include/libsais16x64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.
2626

2727
#define LIBSAIS16X64_VERSION_MAJOR 2
2828
#define LIBSAIS16X64_VERSION_MINOR 8
29-
#define LIBSAIS16X64_VERSION_PATCH 5
30-
#define LIBSAIS16X64_VERSION_STRING "2.8.5"
29+
#define LIBSAIS16X64_VERSION_PATCH 6
30+
#define LIBSAIS16X64_VERSION_STRING "2.8.6"
3131

3232
#ifdef _WIN32
3333
#ifdef LIBSAIS_SHARED

include/libsais64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.
2626

2727
#define LIBSAIS64_VERSION_MAJOR 2
2828
#define LIBSAIS64_VERSION_MINOR 8
29-
#define LIBSAIS64_VERSION_PATCH 5
30-
#define LIBSAIS64_VERSION_STRING "2.8.5"
29+
#define LIBSAIS64_VERSION_PATCH 6
30+
#define LIBSAIS64_VERSION_STRING "2.8.6"
3131

3232
#ifdef _WIN32
3333
#ifdef LIBSAIS_SHARED

src/libsais.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6270,11 +6270,11 @@ static sa_sint_t libsais_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t *
62706270
{
62716271
fs = fs < (SAINT_MAX - n) ? fs : (SAINT_MAX - n);
62726272

6273-
if (k > 0 && ((fs / k >= 6) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6)))
6273+
if (k > 0 && ((fs / k >= 6) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6 && threads == 1)))
62746274
{
62756275
sa_sint_t alignment = (fs - 1024) / k >= 6 ? (sa_sint_t)1024 : (sa_sint_t)16;
62766276
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 6 ? (sa_sint_t *)libsais_align_up(&SA[n + fs - 6 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 6 * (fast_sint_t)k];
6277-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6) ? local_buffer : buckets;
6277+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6 && threads == 1) ? local_buffer : buckets;
62786278

62796279
sa_sint_t m = libsais_count_and_gather_lms_suffixes_32s_4k_omp(T, SA, n, k, buckets, threads, thread_state);
62806280
if (m > 1)
@@ -6329,11 +6329,11 @@ static sa_sint_t libsais_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t *
63296329

63306330
return 0;
63316331
}
6332-
else if (k > 0 && ((fs / k >= 4) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4)))
6332+
else if (k > 0 && (n <= SAINT_MAX / 2) && ((fs / k >= 4) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4 && threads == 1)))
63336333
{
63346334
sa_sint_t alignment = (fs - 1024) / k >= 4 ? (sa_sint_t)1024 : (sa_sint_t)16;
63356335
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 4 ? (sa_sint_t *)libsais_align_up(&SA[n + fs - 4 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 4 * (fast_sint_t)k];
6336-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4) ? local_buffer : buckets;
6336+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4 && threads == 1) ? local_buffer : buckets;
63376337

63386338
sa_sint_t m = libsais_count_and_gather_lms_suffixes_32s_2k_omp(T, SA, n, k, buckets, threads, thread_state);
63396339
if (m > 1)
@@ -6374,11 +6374,11 @@ static sa_sint_t libsais_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t *
63746374

63756375
return 0;
63766376
}
6377-
else if (k > 0 && ((fs / k >= 2) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2)))
6377+
else if (k > 0 && ((fs / k >= 2) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2 && threads == 1)))
63786378
{
63796379
sa_sint_t alignment = (fs - 1024) / k >= 2 ? (sa_sint_t)1024 : (sa_sint_t)16;
63806380
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 2 ? (sa_sint_t *)libsais_align_up(&SA[n + fs - 2 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 2 * (fast_sint_t)k];
6381-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2) ? local_buffer : buckets;
6381+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2 && threads == 1) ? local_buffer : buckets;
63826382

63836383
sa_sint_t m = libsais_count_and_gather_lms_suffixes_32s_2k_omp(T, SA, n, k, buckets, threads, thread_state);
63846384
if (m > 1)

src/libsais16.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6248,11 +6248,11 @@ static sa_sint_t libsais16_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t
62486248
{
62496249
fs = fs < (SAINT_MAX - n) ? fs : (SAINT_MAX - n);
62506250

6251-
if (k > 0 && ((fs / k >= 6) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6)))
6251+
if (k > 0 && ((fs / k >= 6) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6 && threads == 1)))
62526252
{
62536253
sa_sint_t alignment = (fs - 1024) / k >= 6 ? (sa_sint_t)1024 : (sa_sint_t)16;
62546254
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 6 ? (sa_sint_t *)libsais16_align_up(&SA[n + fs - 6 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 6 * (fast_sint_t)k];
6255-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6) ? local_buffer : buckets;
6255+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 6 && threads == 1) ? local_buffer : buckets;
62566256

62576257
sa_sint_t m = libsais16_count_and_gather_lms_suffixes_32s_4k_omp(T, SA, n, k, buckets, threads, thread_state);
62586258
if (m > 1)
@@ -6307,11 +6307,11 @@ static sa_sint_t libsais16_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t
63076307

63086308
return 0;
63096309
}
6310-
else if (k > 0 && ((fs / k >= 4) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4)))
6310+
else if (k > 0 && (n <= SAINT_MAX / 2) && ((fs / k >= 4) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4 && threads == 1)))
63116311
{
63126312
sa_sint_t alignment = (fs - 1024) / k >= 4 ? (sa_sint_t)1024 : (sa_sint_t)16;
63136313
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 4 ? (sa_sint_t *)libsais16_align_up(&SA[n + fs - 4 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 4 * (fast_sint_t)k];
6314-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4) ? local_buffer : buckets;
6314+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 4 && threads == 1) ? local_buffer : buckets;
63156315

63166316
sa_sint_t m = libsais16_count_and_gather_lms_suffixes_32s_2k_omp(T, SA, n, k, buckets, threads, thread_state);
63176317
if (m > 1)
@@ -6352,11 +6352,11 @@ static sa_sint_t libsais16_main_32s_recursion(sa_sint_t * RESTRICT T, sa_sint_t
63526352

63536353
return 0;
63546354
}
6355-
else if (k > 0 && ((fs / k >= 2) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2)))
6355+
else if (k > 0 && ((fs / k >= 2) || (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2 && threads == 1)))
63566356
{
63576357
sa_sint_t alignment = (fs - 1024) / k >= 2 ? (sa_sint_t)1024 : (sa_sint_t)16;
63586358
sa_sint_t * RESTRICT buckets = (fs - alignment) / k >= 2 ? (sa_sint_t *)libsais16_align_up(&SA[n + fs - 2 * (fast_sint_t)k - alignment], (size_t)alignment * sizeof(sa_sint_t)) : &SA[n + fs - 2 * (fast_sint_t)k];
6359-
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2) ? local_buffer : buckets;
6359+
buckets = (LIBSAIS_LOCAL_BUFFER_SIZE / k >= 2 && threads == 1) ? local_buffer : buckets;
63606360

63616361
sa_sint_t m = libsais16_count_and_gather_lms_suffixes_32s_2k_omp(T, SA, n, k, buckets, threads, thread_state);
63626362
if (m > 1)

0 commit comments

Comments
 (0)