Skip to content

Commit c687d7e

Browse files
committed
[TVG] Use heap for XML parser allocs.
1 parent a3b42d8 commit c687d7e

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

thirdparty/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ Files extracted from upstream source:
10411041
Patches:
10421042

10431043
- `0001-revert-tvglines-bezier-precision.patch` (GH-96658)
1044+
- `0002-use-heap-alloc.patch` (GH-109530)
10441045

10451046

10461047
## tinyexr
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
diff --git a/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp b/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp
2+
index 81d5c098a2..4c0a0f53db 100644
3+
--- a/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp
4+
+++ b/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp
5+
@@ -475,11 +475,14 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAt
6+
if (!buf) return false;
7+
8+
end = buf + bufLength;
9+
- key = (char*)alloca(end - buf + 1);
10+
- val = (char*)alloca(end - buf + 1);
11+
12+
if (buf == end) return true;
13+
14+
+ char* key_buf = (char*)malloc(end - buf + 1);
15+
+ char* val_buf = (char*)malloc(end - buf + 1);
16+
+
17+
+ key = key_buf;
18+
+ val = val_buf;
19+
do {
20+
char* sep = (char*)strchr(buf, ':');
21+
next = (char*)strchr(buf, ';');
22+
@@ -487,7 +490,11 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAt
23+
if (auto src = strstr(buf, "src")) {//src tag from css font-face contains extra semicolon
24+
if (src < sep) {
25+
if (next + 1 < end) next = (char*)strchr(next + 1, ';');
26+
- else return true;
27+
+ else {
28+
+ free(key_buf);
29+
+ free(val_buf);
30+
+ return true;
31+
+ }
32+
}
33+
}
34+
35+
@@ -534,6 +541,9 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAt
36+
buf = next + 1;
37+
} while (true);
38+
39+
+ free(key_buf);
40+
+ free(val_buf);
41+
+
42+
return true;
43+
}
44+

thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,26 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAt
475475
if (!buf) return false;
476476

477477
end = buf + bufLength;
478-
key = (char*)alloca(end - buf + 1);
479-
val = (char*)alloca(end - buf + 1);
480478

481479
if (buf == end) return true;
482480

481+
char* key_buf = (char*)malloc(end - buf + 1);
482+
char* val_buf = (char*)malloc(end - buf + 1);
483+
484+
key = key_buf;
485+
val = val_buf;
483486
do {
484487
char* sep = (char*)strchr(buf, ':');
485488
next = (char*)strchr(buf, ';');
486489

487490
if (auto src = strstr(buf, "src")) {//src tag from css font-face contains extra semicolon
488491
if (src < sep) {
489492
if (next + 1 < end) next = (char*)strchr(next + 1, ';');
490-
else return true;
493+
else {
494+
free(key_buf);
495+
free(val_buf);
496+
return true;
497+
}
491498
}
492499
}
493500

@@ -534,6 +541,9 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAt
534541
buf = next + 1;
535542
} while (true);
536543

544+
free(key_buf);
545+
free(val_buf);
546+
537547
return true;
538548
}
539549

0 commit comments

Comments
 (0)