Skip to contentSkip to conversation

zstd: Fix array-index-out-of-bounds UBSAN warning

PATCH In review Nick Terrell 2 participants 2 messages Oct 12, 2023 – Oct 15, 2023 Zstd

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zstd: Fix array-index-out-of-bounds UBSAN warning

From: Nick Terrell <[email protected]>

Zstd used an array of length 1 to mean a flexible array for C89 compatibility. Switch to a C99 flexible array to fix the UBSAN warning.

Tested locally by booting the kernel and writing to and reading from a BtrFS filesystem with zstd compression enabled. I was unable to reproduce the issue before the fix, however it is a trivial change.

---
 lib/zstd/common/fse_decompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/zstd/common/fse_decompress.c +1 -1
index a0d06095be83..8dcb8ca39767 100644
@@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size
 
 typedef struct {
     short ncount[FSE_MAX_SYMBOL_VALUE + 1];
-    FSE_DTable dtable[1]; /* Dynamically sized */
+    FSE_DTable dtable[]; /* Dynamically sized */
 } FSE_DecompressWksp;
 
 
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Nick Terrell

From: Nick Terrell <[email protected]>

Zstd used an array of length 1 to mean a flexible array for C89 compatibility. Switch to a C99 flexible array to fix the UBSAN warning.

Quoted 8 lines

Tested locally by booting the kernel and writing to and reading from a BtrFS filesystem with zstd compression enabled. I was unable to reproduce the issue before the fix, however it is a trivial change.

Thanks! This 1-element conversion doesn't appear to need any sizeof() related changes, so AFAICT this header change is sufficient.

Signature · 1 line
Kees Cook