Debian Codegraph @

debian/patches/CVE-2026-13781

raw
1 From f1b8ba877c07cccc080451fc4f6b17c27fa76581 Mon Sep 17 00:00:00 2001
2 From: Kaylee Lubick <[email protected]>
3 Date: Wed, 27 May 2026 11:55:53 -0400
4 Subject: [PATCH] Restrict deserial types further in SkGlyph and
5 SkCustomTypeface
6
7 Importantly, we don't want typefaces or textblobs in
8 SkPictureBackedGlyphDrawable. In fact, we can look at
9 the code used to make the drawables by our various backends
10 [1][2][3][4] and see we only draw paths and use paints. Thus, we can
11 restrict deserializing these to just those (and the helper tags).
12
13 The SVG fonts could be a bit more complex [5] but chromium doesn't
14 use those (SkGraphics::SetOpenTypeSVGDecoderFactory is never called)
15
16 See also http://graphviz/#57cc93d0c3c73546055bec64fa8e27cb
17
18 [1] https://skia.googlesource.com/skia/+/9da67e212e59fbe4f144a92315ca6f8b876c9c01/src/ports/SkFontHost_FreeType_common.cpp#1567
19 [2] https://skia.googlesource.com/skia/+/9da67e212e59fbe4f144a92315ca6f8b876c9c01/src/ports/SkFontHost_FreeType_common.cpp#1078
20 [3] https://skia.googlesource.com/skia/+/9da67e212e59fbe4f144a92315ca6f8b876c9c01/src/ports/SkScalerContext_win_dw.cpp#677
21 [4] https://skia.googlesource.com/skia/+/9da67e212e59fbe4f144a92315ca6f8b876c9c01/src/ports/SkTypeface_fontations.cpp#1336
22
23 [4] https://skia.googlesource.com/skia/+/9da67e212e59fbe4f144a92315ca6f8b876c9c01/modules/svg/src/SkSVGOpenTypeSVGDecoder.cpp#160
24
25 Bug: https://issues.chromium.org/issues/516457532
26 Fixed: 516457532
27 Change-Id: If852aac417e04f5574dd073138abbe74f792734d
28 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1245617
29 Reviewed-by: Florin Malita <[email protected]>
30 ---
31 include/core/SkSerialProcs.h | 7 +++++++
32 src/core/SkDebugUtils.h | 5 +++++
33 src/core/SkGlyph.cpp | 8 ++++++++
34 src/core/SkPictureData.cpp | 15 +++++++++++++++
35 src/core/SkPictureData.h | 2 +-
36 src/core/SkReadBuffer.h | 8 ++++++++
37 6 files changed, 44 insertions(+), 1 deletion(-)
38
39 --- a/include/core/SkSerialProcs.h
40 +++ b/include/core/SkSerialProcs.h
41 @@ -8,6 +8,7 @@
42 #ifndef SkSerialProcs_DEFINED
43 #define SkSerialProcs_DEFINED
44
45 +#include "include/core/SkFourByteTag.h"
46 #include "include/core/SkRefCnt.h"
47 #include "include/private/base/SkAPI.h"
48
49 @@ -86,6 +87,8 @@
50 using SkDeserialTypefaceStreamProc = sk_sp<SkTypeface> (*)(SkStream&, void* ctx);
51 using SkDeserialTypefaceProc = sk_sp<SkTypeface> (*)(const void* data, size_t length, void* ctx);
52
53 +using SkDeserialAllowTagsProc = bool(*)(SkFourByteTag, void* ctx);
54 +
55 struct SK_API SkSerialProcs {
56 SkSerialPictureProc fPictureProc = nullptr;
57 void* fPictureCtx = nullptr;
58 @@ -115,6 +118,10 @@
59 // parameters and returns a bool). Given that there are only two valid implementations of that
60 // proc, we just insert the bool directly.
61 bool fAllowSkSL = true;
62 +
63 + // Can be used to restrict the tags that will be deserialized from SkPictures.
64 + SkDeserialAllowTagsProc fAllowTagsProc = nullptr;
65 + void* fAllowTagsCtx = nullptr;
66 };
67
68 #endif
69 --- a/src/core/SkDebugUtils.h
70 +++ b/src/core/SkDebugUtils.h
71 @@ -8,6 +8,7 @@
72 #ifndef SkDebugUtils_DEFINED
73 #define SkDebugUtils_DEFINED
74
75 +#include "include/core/SkFourByteTag.h"
76 #include "include/core/SkTileMode.h"
77 #include "include/private/base/SkAssert.h"
78 #include "include/private/base/SkDebug.h"
79 @@ -51,5 +52,9 @@
80 inline void SkDumpBuffer(uint8_t*, int, int, int) {}
81 #endif
82
83 +static inline void SkDumpTag(SkFourByteTag tag) {
84 + SkDebugf("%c%c%c%c", (char)(tag >> 24), (char)(tag >> 16) & 0xFF, (char)(tag >> 8) & 0xFF, (char)tag & 0xFF);
85 +}
86 +
87
88 #endif // SkDebugUtils_DEFINED
89 --- a/src/core/SkGlyph.cpp
90 +++ b/src/core/SkGlyph.cpp
91 @@ -19,6 +19,7 @@
92 #include "include/private/base/SkTo.h"
93 #include "src/base/SkArenaAlloc.h"
94 #include "src/base/SkBezierCurves.h"
95 +#include "src/core/SkPictureData.h"
96 #include "src/core/SkReadBuffer.h"
97 #include "src/core/SkScalerContext.h"
98 #include "src/core/SkWriteBuffer.h"
99 @@ -48,6 +49,13 @@
100 // the deserial procs.
101 SkDeserialProcs procs;
102 procs.fAllowSkSL = buffer.allowSkSL();
103 + procs.fAllowTagsProc = [](SkFourByteTag tag, void*) -> bool {
104 + return tag == SK_PICT_BUFFER_SIZE_TAG ||
105 + tag == SK_PICT_FACTORY_TAG ||
106 + tag == SK_PICT_PAINT_BUFFER_TAG ||
107 + tag == SK_PICT_PATH_BUFFER_TAG ||
108 + tag == SK_PICT_READER_TAG;
109 + };
110 sk_sp<SkPicture> picture = SkPicture::MakeFromData(pictureData.get(), &procs);
111 if (!buffer.validate(picture != nullptr)) {
112 return nullptr;
113 --- a/src/core/SkPictureData.cpp
114 +++ b/src/core/SkPictureData.cpp
115 @@ -18,6 +18,7 @@
116 #include "include/private/base/SkTemplates.h"
117 #include "include/private/base/SkTo.h"
118 #include "src/base/SkAutoMalloc.h"
119 +#include "src/core/SkDebugUtils.h"
120 #include "src/core/SkPicturePriv.h"
121 #include "src/core/SkPictureRecord.h"
122 #include "src/core/SkPtrRecorder.h"
123 @@ -309,6 +310,11 @@
124 const SkDeserialProcs& procs,
125 SkTypefacePlayback* topLevelTFPlayback,
126 int recursionLimit) {
127 + if (procs.fAllowTagsProc && !procs.fAllowTagsProc(tag, procs.fAllowTagsCtx)) {
128 + // Typefaces are always set but if there's 0 of them, we won't mark the stream as invalid
129 + // if the typeface tag is not allowed.
130 + return size == 0;
131 + }
132 switch (tag) {
133 case SK_PICT_READER_TAG:
134 SkASSERT(nullptr == fOpData);
135 @@ -449,6 +455,15 @@
136 }
137
138 void SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t size) {
139 +#if defined(SK_DUMP_TAGS)
140 + SkDebugf("parseBufferTag ");
141 + SkDumpTag(tag);
142 + SkDebugf(" size %u\n", size);
143 +#endif
144 + if (!buffer.allowTags(tag)) {
145 + buffer.validate(size == 0);
146 + return;
147 + }
148 switch (tag) {
149 case SK_PICT_PAINT_BUFFER_TAG: {
150 if (!buffer.validate(SkTFitsIn<int>(size))) {
151 --- a/src/core/SkPictureData.h
152 +++ b/src/core/SkPictureData.h
153 @@ -71,7 +71,7 @@
154 #define SK_PICT_PAINT_BUFFER_TAG SkSetFourByteTag('p', 'n', 't', ' ')
155 #define SK_PICT_PATH_BUFFER_TAG SkSetFourByteTag('p', 't', 'h', ' ')
156 #define SK_PICT_TEXTBLOB_BUFFER_TAG SkSetFourByteTag('b', 'l', 'o', 'b')
157 -#define SK_PICT_SLUG_BUFFER_TAG SkSetFourByteTag('s', 'l', 'u', 'g')
158 +#define SK_PICT_SLUG_BUFFER_TAG SkSetFourByteTag('s', 'l', 'u', 'g')
159 #define SK_PICT_VERTICES_BUFFER_TAG SkSetFourByteTag('v', 'e', 'r', 't')
160 #define SK_PICT_IMAGE_BUFFER_TAG SkSetFourByteTag('i', 'm', 'a', 'g')
161
162 --- a/src/core/SkReadBuffer.h
163 +++ b/src/core/SkReadBuffer.h
164 @@ -11,6 +11,7 @@
165 #include "include/core/SkColor.h"
166 #include "include/core/SkColorFilter.h"
167 #include "include/core/SkFlattenable.h"
168 +#include "include/core/SkFourByteTag.h"
169 #include "include/core/SkImageFilter.h"
170 #include "include/core/SkPaint.h"
171 #include "include/core/SkPathEffect.h"
172 @@ -186,6 +187,13 @@
173 bool allowSkSL() const { return fAllowSkSL; }
174 void setAllowSkSL(bool allow) { fAllowSkSL = allow; }
175
176 + bool allowTags(SkFourByteTag tag) const {
177 + if (!fProcs.fAllowTagsProc) {
178 + return true;
179 + }
180 + return fProcs.fAllowTagsProc(tag, fProcs.fAllowTagsCtx);
181 + }
182 +
183 /**
184 * If isValid is false, sets the buffer to be "invalid". Returns true if the buffer
185 * is still valid.