1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
From 71685eda67178fa374d473ec1431fc459c83bb21 Mon Sep 17 00:00:00 2001
From: Ben Wagner <bungeman@google.com>
Date: Mon, 10 Mar 2025 13:41:23 -0400
Subject: [PATCH] Only call format_message when needed
SkJpegDecoderMgr.cpp#print_message calls into `format_message` to print
informational strings from the jpeg decoder. However, the informational
strings are only output in developer builds where
`SK_PRINT_CODEC_MESSAGES` is defined. As a result this call is usually
just extra work which is then ignored. Move the call of `format_message`
into the argument list of `SkCodecPrintf` so that the call is only
performed if its result is going to be used.
When Skia is compiled to use the system libjpeg-turbo the
`format_message` function pointer is set by an external library to point
at a function inside an external library and is then called by Skia.
This can cause false positive reports [0] from CFI icall [1]. This
change effectively solves this issue by never calling `format_message`
in a CFI enabled build.
[0] https://gitlab.archlinux.org/archlinux/packaging/packages/chromium/-/issues/13
[1] https://clang.llvm.org/docs/ControlFlowIntegrity.html#indirect-function-call-checking
Change-Id: I5a59459e1e87bf8cdb3d7e90481a115a2a77d6cf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/961356
Reviewed-by: Daniel Dilan <danieldilan@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
---
src/codec/SkJpegDecoderMgr.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/codec/SkJpegDecoderMgr.cpp b/src/codec/SkJpegDecoderMgr.cpp
index c905ee1..5ae9573 100644
--- a/src/codec/SkJpegDecoderMgr.cpp
+++ b/src/codec/SkJpegDecoderMgr.cpp
@@ -24,9 +24,11 @@ class SkStream;
* Print information, warning, and error messages
*/
static void print_message(const j_common_ptr info, const char caller[]) {
- char buffer[JMSG_LENGTH_MAX];
- info->err->format_message(info, buffer);
- SkCodecPrintf("libjpeg error %d <%s> from %s\n", info->err->msg_code, buffer, caller);
+ [[maybe_unused]] char buffer[JMSG_LENGTH_MAX];
+ SkCodecPrintf("libjpeg error %d <%s> from %s\n",
+ info->err->msg_code,
+ (info->err->format_message(info, buffer), buffer),
+ caller);
}
/*
|