From 18d27fa10b237fdfcbd8f0c65c19fe009981a3bc Mon Sep 17 00:00:00 2001 From: Noel Gordon Date: Thu, 8 Dec 2022 02:46:29 +0000 Subject: [zlib] make insert_string_simd load window data with zmemcpy Undefined behavior santizer (UBSan) notes that window data loaded using the existing code makes C++ compilers unhappy. C++ Compilers expect data alignment: so loading from an unaligned object is undefined C++ behaviour. Fix this: use zmemcpy to load the window data. All optimizing C++ tested (see bug) output the same instruction sequence, before and after this change. So no change in performance. Bug: 1399295 Test: zlib_bench gzip --compression 6 ~/snappy/testdata/* Change-Id: I90cfd66c803686c3834d88c3bc33833216598836 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4086462 Reviewed-by: Adenilson Cavalcanti Commit-Queue: Noel Gordon Cr-Commit-Position: refs/heads/main@{#1080742} NOKEYCHECK=True GitOrigin-RevId: 36bfeb91012cd6c6897eda645e5375abf14c1c01 --- contrib/optimizations/insert_string.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/optimizations/insert_string.h b/contrib/optimizations/insert_string.h index 2a04f69..c6a296a 100644 --- a/contrib/optimizations/insert_string.h +++ b/contrib/optimizations/insert_string.h @@ -57,10 +57,9 @@ TARGET_CPU_WITH_CRC local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) { Pos ret; - unsigned *ip, val, h = 0; + unsigned val, h = 0; - ip = (unsigned*)&s->window[str]; - val = *ip; + zmemcpy(&val, &s->window[str], sizeof(val)); if (s->level >= 6) val &= 0xFFFFFF; -- cgit v1.2.3