Skip to content

Commit 537f593

Browse files
author
Grok Compression
committed
Fix Windows CI stack buffer overrun (0xc0000409)
- Reduce GRK_PATH_LEN from 4096 to 1024 (Windows MAX_PATH is 260; 1024 is sufficient for extended paths) - Heap-allocate grk_cparameters, grk_decompress_parameters, and grk_stream_params in GrkLRUCacheTest to eliminate ~96KB stack frames that trigger VS 2026 /GS security cookie violations - Add GRK_ENABLE_ASAN CMake option; enable on Windows CI for precise buffer overrun diagnostics
1 parent 2f5264f commit 537f593

4 files changed

Lines changed: 300 additions & 266 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ jobs:
9494
# and build directories, but this is only available with CMake 3.13 and higher.
9595
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
9696
run: |
97-
if [[ "${{ matrix.os }}" != "ubuntu-latest" ]]; then
97+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
98+
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=${{ matrix.shared_libs_flag }} -DBUILD_TESTING:BOOL=ON -DGRK_DATA_ROOT=$DATA_ROOT -DGRK_ENABLE_LIBCURL=OFF -DGRK_ENABLE_ASAN=ON $GENERATOR_PLATFORM
99+
elif [[ "${{ matrix.os }}" != "ubuntu-latest" ]]; then
98100
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=${{ matrix.shared_libs_flag }} -DBUILD_TESTING:BOOL=ON -DGRK_DATA_ROOT=$DATA_ROOT -DGRK_ENABLE_LIBCURL=OFF $GENERATOR_PLATFORM
99101
else
100102
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=${{ matrix.shared_libs_flag }} -DBUILD_TESTING:BOOL=ON -DGRK_DATA_ROOT=$DATA_ROOT -DGRK_ENABLE_LIBCURL=ON $GENERATOR_PLATFORM

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ if(CMAKE_CXX_LINK_PIE_SUPPORTED)
8181
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
8282
endif()
8383

84+
# AddressSanitizer support
85+
option(GRK_ENABLE_ASAN "Enable AddressSanitizer (ASan) for detecting memory errors" OFF)
86+
if(GRK_ENABLE_ASAN)
87+
if(MSVC)
88+
add_compile_options(/fsanitize=address)
89+
# MSVC ASan does not require link flags; the runtime is linked automatically.
90+
else()
91+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
92+
add_link_options(-fsanitize=address)
93+
endif()
94+
endif()
95+
8496
add_compile_options(
8597
$<$<AND:$<COMPILE_LANGUAGE:C,CXX>,$<CONFIG:RelWithDebInfo>>:-fno-omit-frame-pointer>)
8698
add_link_options(

src/lib/core/grok.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ typedef enum _GRK_CODEC_FORMAT
324324
GRK_CODEC_MJ2 /** Motion JPEG 2000 */
325325
} GRK_CODEC_FORMAT;
326326

327-
#define GRK_PATH_LEN 4096 /* Grok maximum supported filename size */
327+
#define GRK_PATH_LEN 1024 /* Grok maximum supported filename size */
328328
#define GRK_MAX_LAYERS 256 /* Grok maximum number of quality layers */
329329

330330
/*

0 commit comments

Comments
 (0)