blob: 017b8080cb18d5d01e26535709a03c606b15b901 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
https://github.com/amadvance/advancecomp/commit/916501836f61ad1beedd943f40ff6f324181fe1d
https://sourceforge.net/p/advancemame/bugs/311/
https://bugs.gentoo.org/959422
From 916501836f61ad1beedd943f40ff6f324181fe1d Mon Sep 17 00:00:00 2001
From: Andrea Mazzoleni <amadvance@gmail.com>
Date: Mon, 7 Jul 2025 14:11:09 +0200
Subject: [PATCH] Fix misaligned access in vectorized comparison by adding
runtime alignment checks
---
zopfli/lz77.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/zopfli/lz77.c b/zopfli/lz77.c
index 9df899d..adb3ee4 100644
--- a/zopfli/lz77.c
+++ b/zopfli/lz77.c
@@ -24,6 +24,7 @@ Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
void ZopfliInitLZ77Store(const unsigned char* data, ZopfliLZ77Store* store) {
store->size = 0;
@@ -299,13 +300,13 @@ static const unsigned char* GetMatch(const unsigned char* scan,
const unsigned char* end,
const unsigned char* safe_end) {
- if (sizeof(size_t) == 8) {
+ if (sizeof(size_t) == 8 && ((uintptr_t)scan % 8 == 0) && ((uintptr_t)match % 8 == 0)) {
/* 8 checks at once per array bounds check (size_t is 64-bit). */
while (scan < safe_end && *((size_t*)scan) == *((size_t*)match)) {
scan += 8;
match += 8;
}
- } else if (sizeof(unsigned int) == 4) {
+ } else if (sizeof(unsigned int) == 4 && ((uintptr_t)scan % 4 == 0) && ((uintptr_t)match % 4 == 0)) {
/* 4 checks at once per array bounds check (unsigned int is 32-bit). */
while (scan < safe_end
&& *((unsigned int*)scan) == *((unsigned int*)match)) {
|