| 1 |
From 5b90a364a9693ed275ba5a99c7ce35f9ea3243b4 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kaylee Lubick <[email protected]> |
| 3 |
Date: Wed, 29 Jul 2026 17:34:47 +0000 |
| 4 |
Subject: [PATCH] Address incorrect handling of a map pointer in SkRP |
| 5 |
|
| 6 |
In pushChildCall, we held on to a pointer from a fChildEffectMap |
| 7 |
and then later dereferenced it. However, in between those |
| 8 |
points was a code path that could grow the map, invalidating |
| 9 |
the pointer. This is demonstrated in the newly added test. |
| 10 |
|
| 11 |
To fix it, we just dereference it earlier. While tracking this |
| 12 |
down, I found a suspicious other usage of the map which works |
| 13 |
in newer C++, but could break in older versions. It's trivial |
| 14 |
to fix Generator::writeFunction, so I handled that as well. |
| 15 |
|
| 16 |
Bug: https://issues.chromium.org/issues/540157141 |
| 17 |
Fixed: 540157141 |
| 18 |
Change-Id: I149b070c31d4cfefa65b30972f0b8b94441e66db |
| 19 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1308776 |
| 20 |
Reviewed-by: Jorge Betancourt <[email protected]> |
| 21 |
Commit-Queue: Kaylee Lubick <[email protected]> |
| 22 |
--- |
| 23 |
.../SkSLRasterPipelineCodeGenerator.cpp | 20 +++++++------ |
| 24 |
tests/RasterPipelineCodeGeneratorTest.cpp | 28 +++++++++++++++++++ |
| 25 |
2 files changed, 40 insertions(+), 8 deletions(-) |
| 26 |
|
| 27 |
diff --git a/src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp b/src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp |
| 28 |
index 484a60970a..730d19bc6a 100644 |
| 29 |
--- a/src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp |
| 30 |
+++ b/src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp |
| 31 |
@@ -1422,10 +1422,13 @@ std::optional<SlotRange> Generator::writeFunction( |
| 32 |
// If we are passing a child effect to a function, we need to add its mapping to our |
| 33 |
// child map. |
| 34 |
if (arg.type().isEffectChild()) { |
| 35 |
- if (int* childIndex = fChildEffectMap.find(arg.as<VariableReference>() |
| 36 |
- .variable())) { |
| 37 |
+ if (int* childIndexPtr = |
| 38 |
+ fChildEffectMap.find(arg.as<VariableReference>().variable())) { |
| 39 |
+ // In earlier C++ versions, the map assignment could cause the map to be |
| 40 |
+ // resized, invalidating the pointer. |
| 41 |
+ int childIndex = *childIndexPtr; |
| 42 |
SkASSERT(!fChildEffectMap.find(¶m)); |
| 43 |
- fChildEffectMap[¶m] = *childIndex; |
| 44 |
+ fChildEffectMap[¶m] = childIndex; |
| 45 |
} |
| 46 |
continue; |
| 47 |
} |
| 48 |
@@ -2809,8 +2812,9 @@ bool Generator::pushConstructorCompound(const AnyConstructor& c) { |
| 49 |
} |
| 50 |
|
| 51 |
bool Generator::pushChildCall(const ChildCall& c) { |
| 52 |
- int* childIdx = fChildEffectMap.find(&c.child()); |
| 53 |
- SkASSERT(childIdx != nullptr); |
| 54 |
+ int* childIdxPtr = fChildEffectMap.find(&c.child()); |
| 55 |
+ SkASSERT(childIdxPtr != nullptr); |
| 56 |
+ int childIdx = *childIdxPtr; // Save this in case pushExpression changes fChildEffectMap |
| 57 |
SkASSERT(!c.arguments().empty()); |
| 58 |
|
| 59 |
// All child calls have at least one argument. |
| 60 |
@@ -2832,7 +2836,7 @@ bool Generator::pushChildCall(const ChildCall& c) { |
| 61 |
|
| 62 |
// Move the argument into src.rgba while also preserving the execution mask. |
| 63 |
fBuilder.exchange_src(); |
| 64 |
- fBuilder.invoke_shader(*childIdx); |
| 65 |
+ fBuilder.invoke_shader(childIdx); |
| 66 |
break; |
| 67 |
} |
| 68 |
case Type::TypeKind::kColorFilter: { |
| 69 |
@@ -2843,7 +2847,7 @@ bool Generator::pushChildCall(const ChildCall& c) { |
| 70 |
|
| 71 |
// Move the argument into src.rgba while also preserving the execution mask. |
| 72 |
fBuilder.exchange_src(); |
| 73 |
- fBuilder.invoke_color_filter(*childIdx); |
| 74 |
+ fBuilder.invoke_color_filter(childIdx); |
| 75 |
break; |
| 76 |
} |
| 77 |
case Type::TypeKind::kBlender: { |
| 78 |
@@ -2861,7 +2865,7 @@ bool Generator::pushChildCall(const ChildCall& c) { |
| 79 |
} |
| 80 |
fBuilder.pop_dst_rgba(); |
| 81 |
fBuilder.exchange_src(); |
| 82 |
- fBuilder.invoke_blender(*childIdx); |
| 83 |
+ fBuilder.invoke_blender(childIdx); |
| 84 |
break; |
| 85 |
} |
| 86 |
default: { |
| 87 |
-- |
| 88 |
2.53.0 |
| 89 |
|