From cdbfebb10f6a4826627445cb643471f05373df8a Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Mon, 23 Sep 2024 07:09:41 -0700 Subject: [PATCH] Fix compress-inl bf16->f32 overrun Caught by Arm hwasan but not x86 asan. PiperOrigin-RevId: 677779421 --- compression/compress-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compression/compress-inl.h b/compression/compress-inl.h index fcec6bc..c29db0f 100644 --- a/compression/compress-inl.h +++ b/compression/compress-inl.h @@ -245,7 +245,7 @@ struct CompressTraits { size_t i = 0; if (num >= N16) { - for (i = 0; i <= num - N16; i += N16) { + for (; i <= num - N16; i += N16) { const VBF packed0 = hn::LoadU(dbf, packed.ptr + packed_ofs + i); hn::StoreU(packed0, dbf, raw + i); } @@ -271,7 +271,7 @@ struct CompressTraits { size_t i = 0; if (num >= 2 * NF) { - for (i = 0; i <= num - 2 * NF; i += 2 * NF) { + for (; i <= num - 2 * NF; i += 2 * NF) { VF raw0, raw1; Load2(df, packed, packed_ofs + i, raw0, raw1); hn::StoreU(raw0, df, raw + i); @@ -289,7 +289,7 @@ struct CompressTraits { // If at most one vector, the first store adds zero padding. Check before // storing the second, because callers only pad to one vector. hn::StoreU(raw0, df, raw + i); - if (remaining >= NF) hn::StoreU(raw1, df, raw + i + NF); + if (remaining > NF) hn::StoreU(raw1, df, raw + i + NF); } } };