| 
 | 1 | +From 93f86001b67609106c658fe0908a9b7931245b8a Mon Sep 17 00:00:00 2001  | 
 | 2 | +From: pedro martelletto <martelletto@google.com>  | 
 | 3 | +Date: Thu, 3 Apr 2025 16:46:42 +0000  | 
 | 4 | +Subject: [PATCH] [zlib] Deflate: move zmemzero after NULL check  | 
 | 5 | + | 
 | 6 | +ZALLOC() might fail, in which case dereferencing the returned pointer  | 
 | 7 | +results in undefined behaviour. N.B. These conditions are not reachable  | 
 | 8 | +from Chromium, as Chromium will abort rather than return nullptr from  | 
 | 9 | +malloc. Found by libfido2's fuzz harness.  | 
 | 10 | +---  | 
 | 11 | + third_party/zlib/deflate.c | 14 +++++++-------  | 
 | 12 | + 1 file changed, 7 insertions(+), 7 deletions(-)  | 
 | 13 | + | 
 | 14 | +diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c  | 
 | 15 | +index 8a5281c2b6cd8..49496bb3b0561 100644  | 
 | 16 | +--- a/third_party/zlib/deflate.c  | 
 | 17 | ++++ b/third_party/zlib/deflate.c  | 
 | 18 | +@@ -485,14 +485,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,  | 
 | 19 | + s->window = (Bytef *) ZALLOC(strm,  | 
 | 20 | + s->w_size + WINDOW_PADDING,  | 
 | 21 | + 2*sizeof(Byte));  | 
 | 22 | +- /* Avoid use of unitialized values in the window, see crbug.com/1137613 and  | 
 | 23 | +- * crbug.com/1144420 */  | 
 | 24 | +- zmemzero(s->window, (s->w_size + WINDOW_PADDING) * (2 * sizeof(Byte)));  | 
 | 25 | + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));  | 
 | 26 | +- /* Avoid use of uninitialized value, see:  | 
 | 27 | +- * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11360  | 
 | 28 | +- */  | 
 | 29 | +- zmemzero(s->prev, s->w_size * sizeof(Pos));  | 
 | 30 | + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));  | 
 | 31 | +   | 
 | 32 | + s->high_water = 0; /* nothing written to s->window yet */  | 
 | 33 | +@@ -551,6 +544,13 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,  | 
 | 34 | + deflateEnd (strm);  | 
 | 35 | + return Z_MEM_ERROR;  | 
 | 36 | + }  | 
 | 37 | ++ /* Avoid use of unitialized values in the window, see crbug.com/1137613 and  | 
 | 38 | ++ * crbug.com/1144420 */  | 
 | 39 | ++ zmemzero(s->window, (s->w_size + WINDOW_PADDING) * (2 * sizeof(Byte)));  | 
 | 40 | ++ /* Avoid use of uninitialized value, see:  | 
 | 41 | ++ * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11360  | 
 | 42 | ++ */  | 
 | 43 | ++ zmemzero(s->prev, s->w_size * sizeof(Pos));  | 
 | 44 | + #ifdef LIT_MEM  | 
 | 45 | + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1));  | 
 | 46 | + s->l_buf = s->pending_buf + (s->lit_bufsize << 2);  | 
 | 47 | +--   | 
 | 48 | +2.49.0.504.g3bcea36a83-goog  | 
 | 49 | + | 
0 commit comments