app-arch/advancecomp: fix unaligned access

Closes: https://bugs.gentoo.org/959422
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2025-07-25 06:35:26 +01:00
parent 152fbed629
commit 1bee2f710c
2 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DESCRIPTION="Recompress ZIP, PNG and MNG, considerably improving compression"
HOMEPAGE="
https://www.advancemame.it/comp-readme.html
https://github.com/amadvance/advancecomp/
"
SRC_URI="
https://github.com/amadvance/advancecomp/releases/download/v${PV}/${P}.tar.gz
"
LICENSE="GPL-2+ Apache-2.0 LGPL-2.1+ MIT"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~riscv ~x86"
RDEPEND="
app-arch/bzip2:=
sys-libs/zlib:=
"
DEPEND="
${RDEPEND}
"
PATCHES=(
"${FILESDIR}"/${PN}-2.6-unaligned-access.patch
)
src_configure() {
local myconf=(
--enable-bzip2
# (--disable-* arguments are mishandled)
# --disable-debug
# --disable-valgrind
)
econf "${myconf[@]}"
}
src_test() {
# Tests seem to rely on exact output:
# https://sourceforge.net/p/advancemame/bugs/270/
#default
# Do a smoke test given we can't run the real testsuite
cp "${DISTDIR}"/${P}.tar.gz "${T}" || die
local level
for level in -0 -1 -2 -3 -4 ; do
./advdef -z ${level} "${T}"/${P}.tar.gz || die
done
}
src_install() {
default
dodoc HISTORY
}

View File

@@ -0,0 +1,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)) {