public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Akira TAGOH <akira@tagoh.org>
To: git-commits@fedoraproject.org
Subject: [rpms/fontconfig] f43: Backport a patch to fix OOB access in FcCharSetMerge.
Date: Wed, 18 Nov 2026 14:04:27 GMT	[thread overview]
Message-ID: <179501066751.1.18020267453096960369.rpms-fontconfig-f2e0f6d07c01@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/fontconfig
Branch : f43
Commit : f2e0f6d07c01f8fe7ad57ee9990e0f73d6129e89
Author : Akira TAGOH <akira@tagoh.org>
Date   : 2026-11-18T22:52:23+09:00
Stats  : +179/-1 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/fontconfig/c/f2e0f6d07c01f8fe7ad57ee9990e0f73d6129e89?branch=f43

Log:
Backport a patch to fix OOB access in FcCharSetMerge.

---
diff --git a/fontconfig-fix-fccharsetmerge-oob.patch b/fontconfig-fix-fccharsetmerge-oob.patch
new file mode 100644
index 0000000..7e5af9c
--- /dev/null
+++ b/fontconfig-fix-fccharsetmerge-oob.patch
@@ -0,0 +1,174 @@
+From b43de2b59c6d3890c4ecdf250ce3d78c43569d16 Mon Sep 17 00:00:00 2001
+From: Akira TAGOH <akira@tagoh.org>
+Date: Wed, 18 Nov 2026 22:48:09 +0900
+Subject: [PATCH] Fix out-of-bounds access in FcCharSetMerge when merging page
+ 0xffff
+
+FcCharSetMerge walks the pages of both charsets in order.  Once every
+page of the destination charset has been consumed, the loop used the
+sentinel value ~0 to stand in for "there are no more pages".  Page
+numbers are stored as 16 bits, so that sentinel became 0xffff -- which
+is itself a valid page number, covering the characters U+FFFF00 through
+U+FFFFFF.
+
+As a result, when the source charset contained page 0xffff and the
+destination had already run out of pages, the sentinel compared equal to
+that real page.  The merge then treated it as an existing page and read
+the leaf one entry past the end of the destination's leaf array.
+
+Widen the page-number comparison variables to 32 bits so the sentinel
+(0xffffffff) can no longer equal any valid page number.  The 0xffff page
+is then correctly appended instead.
+
+Changelog: security
+---
+ src/fccharset.c           | 10 ++++-
+ test/meson.build          |  1 +
+ test/test-charset-merge.c | 95 +++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 105 insertions(+), 1 deletion(-)
+ create mode 100644 test/test-charset-merge.c
+
+diff --git a/src/fccharset.c b/src/fccharset.c
+index 67d4c940..b879b6cc 100644
+--- a/src/fccharset.c
++++ b/src/fccharset.c
+@@ -484,7 +484,7 @@ FcBool
+ FcCharSetMerge (FcCharSet *a, const FcCharSet *b, FcBool *changed)
+ {
+     int      ai = 0, bi = 0;
+-    FcChar16 an, bn;
++    FcChar32 an, bn;
+ 
+     if (!a || !b)
+ 	return FcFalse;
+@@ -502,6 +502,14 @@ FcCharSetMerge (FcCharSet *a, const FcCharSet *b, FcBool *changed)
+     }
+ 
+     while (bi < b->num) {
++	/*
++	 * Once a is exhausted, use a sentinel greater than any valid page
++	 * number.  Page numbers are 16-bit (FcCharSetNumbers is FcChar16), so
++	 * 0xffff is itself a legitimate page (chars U+FFFF00..U+FFFFFF).  Keep
++	 * an/bn as FcChar32 so the ~0 sentinel never collides with a real page;
++	 * otherwise a b page of 0xffff would be unioned into a leaf one past the
++	 * end of a's leaves array instead of being appended.
++	 */
+ 	an = ai < a->num ? FcCharSetNumbers (a)[ai] : ~0;
+ 	bn = FcCharSetNumbers (b)[bi];
+ 
+diff --git a/test/meson.build b/test/meson.build
+index 50e19067..b0c67147 100644
+--- a/test/meson.build
++++ b/test/meson.build
+@@ -22,6 +22,7 @@ tests = [
+   ['test-issue180.c'],
+   ['test-family-matching.c'],
+   ['test-ptrlist.c', {'include_directories': include_directories('../src'), 'dependencies': libintl_dep}],
++  ['test-charset-merge.c'],
+ ]
+ tests_not_parallel = []
+ 
+diff --git a/test/test-charset-merge.c b/test/test-charset-merge.c
+new file mode 100644
+index 00000000..2fa7dff8
+--- /dev/null
++++ b/test/test-charset-merge.c
+@@ -0,0 +1,95 @@
++/* Copyright (C) 2026 fontconfig Authors */
++/* SPDX-License-Identifier: HPND */
++
++/*
++ * Regression test for an out-of-bounds access in FcCharSetMerge().
++ *
++ * Page numbers in a charset are 16-bit, so 0xffff (covering the characters
++ * U+FFFF00..U+FFFFFF) is a legitimate page.  FcCharSetMerge() used ~0 cast to
++ * FcChar16 (== 0xffff) as the "a is exhausted" sentinel, so when b carried a
++ * 0xffff page and a had run out of leaves, the sentinel compared equal to the
++ * real page and the merge unioned into FcCharSetLeaf(a, a->num) -- one past the
++ * end of a's leaves array.  A font with such a cmap entry could therefore crash
++ * any caller that sorts fonts (FcFontSort / FcFontSetSort).
++ *
++ * These cases exercise the merge directly, with no font file required.
++ */
++
++#include <fontconfig/fontconfig.h>
++
++#include <stdio.h>
++#include <stdlib.h>
++
++/* Highest page (0xffff) == the value that used to collide with the sentinel. */
++#define TOP_PAGE_CHAR 0xffff42
++
++static int
++check (const char *name, FcCharSet *a, FcCharSet *b)
++{
++    FcBool changed = FcFalse;
++
++    /* Without the fix this reads/writes past the end of a's leaves array. */
++    if (!FcCharSetMerge (a, b, &changed)) {
++	fprintf (stderr, "%s: FcCharSetMerge failed\n", name);
++	return 1;
++    }
++    if (!changed) {
++	fprintf (stderr, "%s: expected changed == FcTrue\n", name);
++	return 1;
++    }
++    if (!FcCharSetHasChar (a, TOP_PAGE_CHAR)) {
++	fprintf (stderr, "%s: merged charset is missing U+%06X\n",
++	         name, (unsigned)TOP_PAGE_CHAR);
++	return 1;
++    }
++    return 0;
++}
++
++int
++main (void)
++{
++    FcCharSet *a, *b;
++    int        ret = 0;
++
++    /* Case 1: a is empty, b holds only the top page. */
++    a = FcCharSetCreate ();
++    b = FcCharSetCreate ();
++    FcCharSetAddChar (b, TOP_PAGE_CHAR);
++    ret |= check ("empty-a", a, b);
++    FcCharSetDestroy (a);
++    FcCharSetDestroy (b);
++
++    /* Case 2: a runs out before b's top page (a has only a lower page). */
++    a = FcCharSetCreate ();
++    b = FcCharSetCreate ();
++    FcCharSetAddChar (a, 0x41);
++    FcCharSetAddChar (b, 0x41);
++    FcCharSetAddChar (b, 0x5000);
++    FcCharSetAddChar (b, TOP_PAGE_CHAR);
++    ret |= check ("short-a", a, b);
++    if (!FcCharSetHasChar (a, 0x5000)) {
++	fprintf (stderr, "short-a: merged charset is missing U+5000\n");
++	ret = 1;
++    }
++    FcCharSetDestroy (a);
++    FcCharSetDestroy (b);
++
++    /* Case 3: both a and b already carry the top page (union in place). */
++    a = FcCharSetCreate ();
++    b = FcCharSetCreate ();
++    FcCharSetAddChar (a, TOP_PAGE_CHAR);
++    FcCharSetAddChar (b, 0xffff01);
++    ret |= check ("shared-top", a, b);
++    if (!FcCharSetHasChar (a, 0xffff01)) {
++	fprintf (stderr, "shared-top: merged charset is missing U+FFFF01\n");
++	ret = 1;
++    }
++    FcCharSetDestroy (a);
++    FcCharSetDestroy (b);
++
++    FcFini ();
++
++    if (ret == 0)
++	printf ("PASS\n");
++    return ret;
++}
+-- 
+2.56.1
+

diff --git a/fontconfig.spec b/fontconfig.spec
index 527381f..11afd72 100644
--- a/fontconfig.spec
+++ b/fontconfig.spec
@@ -5,7 +5,7 @@
 Summary:	Font configuration and customization library
 Name:		fontconfig
 Version:	2.17.0
-Release:	4%{?dist}
+Release:	5%{?dist}
 # src/ftglue.[ch] is in Public Domain
 # src/fccache.c contains Public Domain code
 ## https://gitlab.com/fedora/legal/fedora-license-data/-/issues/177
@@ -23,6 +23,7 @@ Patch4:		%{name}-drop-lang-from-pkgkit-format.patch
 Patch5:		%{name}-disable-network-required-test.patch
 Patch6:		%{name}-lower-nonlatin-conf.patch
 Patch7:		%{name}-fix-crash.patch
+Patch8:		%{name}-fix-fccharsetmerge-oob.patch
 
 BuildRequires:	libxml2-devel
 BuildRequires:	freetype-devel >= %{freetype_version}
@@ -204,6 +205,9 @@ fi
 %doc fontconfig-devel.txt fontconfig-devel.html
 
 %changelog
+* Wed Nov 18 2026 Akira TAGOH <tagoh@redhat.com> - 2.17.0-5
+- Backport a patch to fix OOB access in FcCharSetMerge.
+
 * Fri Jan 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 2.17.0-4
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_44_Mass_Rebuild
 

                 reply	other threads:[~2026-11-18 14:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179501066751.1.18020267453096960369.rpms-fontconfig-f2e0f6d07c01@fedoraproject.org \
    --to=akira@tagoh.org \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox