Skip to content

Commit 41821e4

Browse files
[AUTO-CHERRYPICK] Fix CVE-2024-56732 for harfbuzz - branch 3.0-dev (#11866)
Co-authored-by: Sudipta Pandit <sudpandit@microsoft.com>
1 parent 1ecba0b commit 41821e4

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From 1767f99e2e2196c3fcae27db6d8b60098d3f6d26 Mon Sep 17 00:00:00 2001
2+
From: Behdad Esfahbod <behdad@behdad.org>
3+
Date: Sun, 10 Nov 2024 22:43:28 -0700
4+
Subject: [PATCH] [cairo] Guard hb_cairo_glyphs_from_buffer() against bad UTF-8
5+
6+
Previously it was assuming valid UTF-8.
7+
---
8+
src/hb-cairo.cc | 2 ++
9+
src/hb-utf.hh | 6 ++++--
10+
2 files changed, 6 insertions(+), 2 deletions(-)
11+
12+
diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc
13+
index d8b582c4908..4d22ae059ff 100644
14+
--- a/src/hb-cairo.cc
15+
+++ b/src/hb-cairo.cc
16+
@@ -1000,6 +1000,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer,
17+
end = start + hb_glyph[i].cluster - hb_glyph[i+1].cluster;
18+
else
19+
end = (const char *) hb_utf_offset_to_pointer<hb_utf8_t> ((const uint8_t *) start,
20+
+ (const uint8_t *) utf8, utf8_len,
21+
(signed) (hb_glyph[i].cluster - hb_glyph[i+1].cluster));
22+
(*clusters)[cluster].num_bytes = end - start;
23+
start = end;
24+
@@ -1020,6 +1021,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer,
25+
end = start + hb_glyph[i].cluster - hb_glyph[i-1].cluster;
26+
else
27+
end = (const char *) hb_utf_offset_to_pointer<hb_utf8_t> ((const uint8_t *) start,
28+
+ (const uint8_t *) utf8, utf8_len,
29+
(signed) (hb_glyph[i].cluster - hb_glyph[i-1].cluster));
30+
(*clusters)[cluster].num_bytes = end - start;
31+
start = end;
32+
diff --git a/src/hb-utf.hh b/src/hb-utf.hh
33+
index 1120bd1cccf..6db9bf2fd79 100644
34+
--- a/src/hb-utf.hh
35+
+++ b/src/hb-utf.hh
36+
@@ -458,19 +458,21 @@ struct hb_ascii_t
37+
template <typename utf_t>
38+
static inline const typename utf_t::codepoint_t *
39+
hb_utf_offset_to_pointer (const typename utf_t::codepoint_t *start,
40+
+ const typename utf_t::codepoint_t *text,
41+
+ unsigned text_len,
42+
signed offset)
43+
{
44+
hb_codepoint_t unicode;
45+
46+
while (offset-- > 0)
47+
start = utf_t::next (start,
48+
- start + utf_t::max_len,
49+
+ text + text_len,
50+
&unicode,
51+
HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT);
52+
53+
while (offset++ < 0)
54+
start = utf_t::prev (start,
55+
- start - utf_t::max_len,
56+
+ text,
57+
&unicode,
58+
HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT);
59+

SPECS/harfbuzz/harfbuzz.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Summary: opentype text shaping engine
22
Name: harfbuzz
33
Version: 8.3.0
4-
Release: 2%{?dist}
4+
Release: 3%{?dist}
55
License: MIT
66
Vendor: Microsoft Corporation
77
Distribution: Azure Linux
88
Group: System Environment/Libraries
99
URL: https://harfbuzz.github.io/
1010
Source0: https://github.com/%{name}/%{name}/releases/download/%{version}/%{name}-%{version}.tar.xz
11+
Patch0: CVE-2024-56732.patch
1112
BuildRequires: pkgconfig(cairo)
1213
BuildRequires: pkgconfig(freetype2)
1314
BuildRequires: pkgconfig(glib-2.0)
@@ -90,6 +91,9 @@ find . -type f -name "*.py" -exec sed -i'' -e '1 s|^#!\s*/usr/bin/env\s\+python3
9091
%{_libdir}/libharfbuzz-icu.so.*
9192

9293
%changelog
94+
* Wed Jan 08 2025 Sudipta Pandit <sudpandit@microsoft.com> - 8.3.0-3
95+
- Patch for CVE-2024-56732
96+
9397
* Wed Jul 31 2024 Andrew Phelps <anphel@microsoft.com> - 8.3.0-2
9498
- Update file listings to remove duplicate files
9599

0 commit comments

Comments
 (0)