LibGfx: Copy into a u32 in LZWDecoder::next_code() instead of casting

This results in unaligned reads sometimes, depending on the layout of
the underlying buffer. Caught by UBSAN.
This commit is contained in:
Andrew Kaster 2021-05-24 08:23:35 -06:00 committed by Andreas Kling
commit 480802805f
Notes: sideshowbarker 2024-07-18 17:18:50 +09:00

View file

@ -187,8 +187,9 @@ public:
const u32* addr = (const u32*)&padded_last_bytes;
m_current_code = (*addr & mask) >> current_bit_offset;
} else {
const u32* addr = (const u32*)&m_lzw_bytes.at(current_byte_index);
m_current_code = (*addr & mask) >> current_bit_offset;
u32 tmp_word;
memcpy(&tmp_word, &m_lzw_bytes.at(current_byte_index), sizeof(u32));
m_current_code = (tmp_word & mask) >> current_bit_offset;
}
if (m_current_code > m_code_table.size()) {