summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/GIFLoader.cpp
diff options
context:
space:
mode:
authorAndrew Kaster <andrewdkaster@gmail.com>2021-05-24 08:23:35 -0600
committerAndreas Kling <kling@serenityos.org>2021-05-27 15:18:03 +0200
commit480802805fc11e079c6f3f65c2e9886136d05f86 (patch)
tree38dfea230e365691bf20e0a01deda62b21602560 /Userland/Libraries/LibGfx/GIFLoader.cpp
parent74da0f24f0c99d2cb1646234e841bd42a7fb8c99 (diff)
downloadserenity-480802805fc11e079c6f3f65c2e9886136d05f86.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGfx/GIFLoader.cpp')
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp
index d8b60c0dbb..16fca946d6 100644
--- a/Userland/Libraries/LibGfx/GIFLoader.cpp
+++ b/Userland/Libraries/LibGfx/GIFLoader.cpp
@@ -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()) {