From c5da03f448485044835046fc31f9a734060ffb99 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Thu, 21 Mar 2019 09:29:31 -0700 Subject: entry_name_utils-inl.h: clear top bit before shifting Attempting to shift a uint8_t which has the top bit set results in a value outside of the range allowable for a uint8_t. The process of converting this value back to a uint8_t triggers ubsan's implicit-conversion sanitizer. Ensure the high order bit is stripped before shifting, so that the shifted value fits into the allowable uint8_t range. This change is necessary to enable integer sanitization on this code. Somewhat related to Bug: 122975762 Test: atest ziparchive-tests Change-Id: I940c8b2828ac88348d80f731274b990e35de6631 --- libziparchive/entry_name_utils-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libziparchive/entry_name_utils-inl.h') diff --git a/libziparchive/entry_name_utils-inl.h b/libziparchive/entry_name_utils-inl.h index 5fc2fb458..171458690 100644 --- a/libziparchive/entry_name_utils-inl.h +++ b/libziparchive/entry_name_utils-inl.h @@ -35,7 +35,7 @@ inline bool IsValidEntryName(const uint8_t* entry_name, const size_t length) { return false; } else { // 2-5 byte sequences. - for (uint8_t first = byte << 1; first & 0x80; first <<= 1) { + for (uint8_t first = (byte & 0x7f) << 1; first & 0x80; first = (first & 0x7f) << 1) { ++i; // Missing continuation byte.. -- cgit v1.2.3