Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/glib/CVE-2026-16118.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From ca75aff83af9875ea2ad2bfbe48a85dfd99c2ce5 Mon Sep 17 00:00:00 2001
From: Kashyap Ekbote <kashyap.ekbote@gmail.com>
Date: Wed, 5 Aug 2026 20:50:10 +0530
Subject: [PATCH] Fix CVE-2026-16118: heap-buffer-overflow in xdgmimemagic.c

Fix out-of-bounds write in the byte-swap routine of
_xdg_mime_magic_parse_magic_line(). On little-endian systems, the
write side of the swap casts the base pointer to a wider type before
adding the byte offset, causing pointer arithmetic to scale by
sizeof(type) instead of 1. With value_length=4 and word_size=2, the
loop writes 2 bytes past the allocated matchlet->value buffer at i=2.

Parenthesize (ptr + i) before the cast so both the read and write
sides use byte offsets.

Upstream: https://gitlab.freedesktop.org/xdg/xdgmime/-/work_items/41
---
gio/xdgmime/xdgmimemagic.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gio/xdgmime/xdgmimemagic.c b/gio/xdgmime/xdgmimemagic.c
index 98a1274c87..fe374eb4e5 100644
--- a/gio/xdgmime/xdgmimemagic.c
+++ b/gio/xdgmime/xdgmimemagic.c
@@ -483,15 +483,15 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
for (i = 0; i < matchlet->value_length; i = i + matchlet->word_size)
{
if (matchlet->word_size == 2)
- *((xdg_uint16_t *) matchlet->value + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->value + i)));
+ *((xdg_uint16_t *) (matchlet->value + i)) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->value + i)));
else if (matchlet->word_size == 4)
- *((xdg_uint32_t *) matchlet->value + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->value + i)));
+ *((xdg_uint32_t *) (matchlet->value + i)) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->value + i)));
if (matchlet->mask)
{
if (matchlet->word_size == 2)
- *((xdg_uint16_t *) matchlet->mask + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->mask + i)));
+ *((xdg_uint16_t *) (matchlet->mask + i)) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->mask + i)));
else if (matchlet->word_size == 4)
- *((xdg_uint32_t *) matchlet->mask + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->mask + i)));
+ *((xdg_uint32_t *) (matchlet->mask + i)) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->mask + i)));

}
}
--
GitLab

26 changes: 24 additions & 2 deletions packages/glib/build.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let { Attrs, BuildSpec, Local, OutputBin, OutputData, OutputLib, Source, .. } =
let base = import "../base/build.ncl" in
let meson = import "../meson/build.ncl" in
let ninja = import "../ninja/build.ncl" in
let patch = import "../patch/build.ncl" in
let pkgconf = import "../pkgconf/build.ncl" in
let toolchain = import "../toolchain/build.ncl" in
let python = import "../python/build.ncl" in
Expand All @@ -11,20 +12,31 @@ let zlib = import "../zlib/build.ncl" in
let util-linux = import "../util-linux/build.ncl" in
let glibc = import "../glibc/build.ncl" in

let version = "2.88.3" in
let version = "2.88.4" in
{
name = "glib",
build_deps = [
{ file = "build.sh" } | Local,
{
url = "gs://minimal-staging-archives/glib-%{version}.tar.xz",
sha256 = "ab24d24e698dfa1e408b7bcdb508f4aafc906185a8b8ce72fdf79bbbdc9b383b",
sha256 = "25fd169f3b2f91fe2391ad297883ce0fcf30c69fc789ffd1c9672d1332b1c5a8",
extract = true,
strip_prefix = "glib-%{version}",
} | Source,
# Security backport: CVE-2026-16118, heap overflow in the bundled xdgmime's
# _xdg_mime_magic_parse_magic_line (gio/xdgmime/xdgmimemagic.c). On
# little-endian hosts the byte-swap of a `~2`/`~4` magic value cast before
# adding the byte offset, so it wrote 2 bytes past matchlet->value. Reached
# from a MIME magic file in a user-writable XDG data dir. Upstream
# GNOME/glib ca75aff83af9 (MR !5286, merged 2026-08-07) on main only:
# 2.88.4's security backports (!5394) leave gio/xdgmime/ unchanged, so
# the cast is still unparenthesized there. Debian carries it as 2.88.3-3.
# Verbatim upstream commit.
{ file = "CVE-2026-16118.patch" } | Local,
base,
meson,
ninja,
patch,
pkgconf,
toolchain,
python,
Expand All @@ -51,5 +63,15 @@ let version = "2.88.3" in
{
upstream_version = version,
license_spdx = "LGPL-2.1-or-later",
# Canonical upstream is gitlab.gnome.org/GNOME/glib; github.com/GNOME/glib
# is GNOME's own read-only mirror (same tags, same SHAs). Declared as the
# mirror for the same reason as libxml2/libxslt: the scanner's GithubRepo
# arm keeps the curated gnome:glib CPE identity in play, which a Gitlab
# provenance would bypass (gominimal/pkgmgr-rs#848).
source_provenance = {
category = 'GithubRepo,
owner = "GNOME",
repo = "glib",
},
} | Attrs,
} | BuildSpec
28 changes: 28 additions & 0 deletions packages/glib/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/sh
set -e

# Security backport (see build.ncl). `set -e` plus patch's non-zero exit on a
# rejected hunk means a stale patch ABORTS the build rather than silently
# shipping an unpatched libgio.
patch -Np1 -i "CVE-2026-16118.patch" # gio/xdgmime/xdgmimemagic.c byte-swap heap overflow

case $(uname -m) in
x86_64) MARCH="-march=x86-64-v3" ;;
aarch64) MARCH="-march=armv8-a" ;;
Expand All @@ -20,3 +25,26 @@ meson setup --prefix=/usr --buildtype=release \
..
ninja
DESTDIR="$OUTPUT_DIR" ninja install

# Regression test for CVE-2026-16118, using the just-installed `gio`. The bug
# is observable, not only a memory error. The unpatched swap loop writes word
# i to byte offset i*word_size, so for a 4-byte `~2` value it swaps the first
# word, writes the second word out of bounds, and leaves bytes 2..3 unswapped.
# A magic rule `>0=ABCD~2` must therefore become the byte string "BADC" on
# little-endian hosts and match a file that starts with "BADC". Unpatched it
# stays "BACD", the file goes unrecognised, and this test fails. On big-endian
# hosts no swap happens at all, so the test would not be meaningful there.
if [ "$(printf '\001\000' | od -An -tu2 | tr -d ' ')" = "1" ]; then
t="$(pwd)/cve-2026-16118"
mkdir -p "$t/home/mime" "$t/sys"
printf 'MIME-Magic\000\n[50:application/x-cve-2026-16118]\n>0=\000\004ABCD~2\n' \
> "$t/home/mime/magic"
printf 'BADC\001\002\003\004\377\376' > "$t/probe"
got=$(XDG_DATA_HOME="$t/home" XDG_DATA_DIRS="$t/sys" \
LD_LIBRARY_PATH="$OUTPUT_DIR/usr/lib" \
"$OUTPUT_DIR/usr/bin/gio" info -a standard::content-type "$t/probe" \
| sed -n 's/^ *standard::content-type: //p')
echo "CVE-2026-16118 probe content type: '$got'"
[ "$got" = "application/x-cve-2026-16118" ]
rm -rf "$t"
fi
Loading