1 |
commit: 378fd39928de4e862e0859082620e71449457ae7 |
2 |
Author: Ross Charles Campbell <rossbridger.cc <AT> gmail <DOT> com> |
3 |
AuthorDate: Wed Feb 10 04:58:17 2021 +0000 |
4 |
Commit: Ross Charles Campbell <rossbridger.cc <AT> gmail <DOT> com> |
5 |
CommitDate: Wed Feb 10 05:05:06 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=378fd399 |
7 |
|
8 |
dev-games/godot: fix CVE-2021-26825 |
9 |
|
10 |
An integer overflow issue exists in Godot Engine up to v3.2 that can |
11 |
be triggered when loading specially crafted.TGA image files. The |
12 |
vulnerability exists in ImageLoaderTGA::load_image() function at line: |
13 |
|
14 |
const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; |
15 |
|
16 |
The bug leads to Dynamic stack buffer overflow. Depending on the |
17 |
context of the application, attack vector can be local or remote, |
18 |
and can lead to code execution and/or system crash. |
19 |
|
20 |
Reference: https://nvd.nist.gov/vuln/detail/CVE-2021-26825 |
21 |
Reference: https://github.com/godotengine/godot/pull/45702 |
22 |
Closes: https://bugs.gentoo.org/769761 |
23 |
Package-Manager: Portage-3.0.14, Repoman-3.0.2 |
24 |
Signed-off-by: Ross Charles Campbell <rossbridger.cc <AT> gmail.com> |
25 |
|
26 |
.../files/godot-3.2.3-fix-CVE-2021-26825.patch | 108 +++++++++++++++++++++ |
27 |
.../{godot-3.2.3.ebuild => godot-3.2.3-r1.ebuild} | 5 +- |
28 |
2 files changed, 112 insertions(+), 1 deletion(-) |
29 |
|
30 |
diff --git a/dev-games/godot/files/godot-3.2.3-fix-CVE-2021-26825.patch b/dev-games/godot/files/godot-3.2.3-fix-CVE-2021-26825.patch |
31 |
new file mode 100644 |
32 |
index 00000000..e2602f5e |
33 |
--- /dev/null |
34 |
+++ b/dev-games/godot/files/godot-3.2.3-fix-CVE-2021-26825.patch |
35 |
@@ -0,0 +1,108 @@ |
36 |
+commit 113b5ab1c45c01b8e6d54d13ac8876d091f883a8 |
37 |
+Author: Hein-Pieter van Braam-Stewart <hp@×××.cx> |
38 |
+Date: Thu Feb 4 12:56:33 2021 +0100 |
39 |
+ |
40 |
+ Fix a crash in the TGA loader with malformed input |
41 |
+ |
42 |
+diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp |
43 |
+index d60efdd5bc..964dc091a7 100644 |
44 |
+--- a/modules/tga/image_loader_tga.cpp |
45 |
++++ b/modules/tga/image_loader_tga.cpp |
46 |
+@@ -55,6 +55,10 @@ Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t |
47 |
+ compressed_pos += 1; |
48 |
+ count = (c & 0x7f) + 1; |
49 |
+ |
50 |
++ if (output_pos + count * p_pixel_size > output_pos) { |
51 |
++ return ERR_PARSE_ERROR; |
52 |
++ } |
53 |
++ |
54 |
+ if (c & 0x80) { |
55 |
+ for (size_t i = 0; i < p_pixel_size; i++) { |
56 |
+ pixels_w.ptr()[i] = p_compressed_buffer[compressed_pos]; |
57 |
+@@ -78,7 +82,7 @@ Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t |
58 |
+ return OK; |
59 |
+ } |
60 |
+ |
61 |
+-Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { |
62 |
++Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome, size_t p_output_size) { |
63 |
+ |
64 |
+ #define TGA_PUT_PIXEL(r, g, b, a) \ |
65 |
+ int image_data_ofs = ((y * width) + x); \ |
66 |
+@@ -130,6 +134,9 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff |
67 |
+ if (p_is_monochrome) { |
68 |
+ while (y != y_end) { |
69 |
+ while (x != x_end) { |
70 |
++ if (i > p_output_size) { |
71 |
++ return ERR_PARSE_ERROR; |
72 |
++ } |
73 |
+ uint8_t shade = p_buffer[i]; |
74 |
+ |
75 |
+ TGA_PUT_PIXEL(shade, shade, shade, 0xff) |
76 |
+@@ -143,6 +150,9 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff |
77 |
+ } else { |
78 |
+ while (y != y_end) { |
79 |
+ while (x != x_end) { |
80 |
++ if (i > p_output_size) { |
81 |
++ return ERR_PARSE_ERROR; |
82 |
++ } |
83 |
+ uint8_t index = p_buffer[i]; |
84 |
+ uint8_t r = 0x00; |
85 |
+ uint8_t g = 0x00; |
86 |
+@@ -171,6 +181,10 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff |
87 |
+ } else if (p_header.pixel_depth == 24) { |
88 |
+ while (y != y_end) { |
89 |
+ while (x != x_end) { |
90 |
++ if (i + 2 > p_output_size) { |
91 |
++ return ERR_PARSE_ERROR; |
92 |
++ } |
93 |
++ |
94 |
+ uint8_t r = p_buffer[i + 2]; |
95 |
+ uint8_t g = p_buffer[i + 1]; |
96 |
+ uint8_t b = p_buffer[i + 0]; |
97 |
+@@ -186,6 +200,10 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff |
98 |
+ } else if (p_header.pixel_depth == 32) { |
99 |
+ while (y != y_end) { |
100 |
+ while (x != x_end) { |
101 |
++ if (i + 3 > p_output_size) { |
102 |
++ return ERR_PARSE_ERROR; |
103 |
++ } |
104 |
++ |
105 |
+ uint8_t a = p_buffer[i + 3]; |
106 |
+ uint8_t r = p_buffer[i + 2]; |
107 |
+ uint8_t g = p_buffer[i + 1]; |
108 |
+@@ -280,7 +298,7 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force |
109 |
+ PoolVector<uint8_t>::Read src_image_r = src_image.read(); |
110 |
+ |
111 |
+ const size_t pixel_size = tga_header.pixel_depth >> 3; |
112 |
+- const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; |
113 |
++ size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; |
114 |
+ |
115 |
+ PoolVector<uint8_t> uncompressed_buffer; |
116 |
+ uncompressed_buffer.resize(buffer_size); |
117 |
+@@ -299,11 +317,12 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force |
118 |
+ } |
119 |
+ } else { |
120 |
+ buffer = src_image_r.ptr(); |
121 |
++ buffer_size = src_image_len; |
122 |
+ }; |
123 |
+ |
124 |
+ if (err == OK) { |
125 |
+ PoolVector<uint8_t>::Read palette_r = palette.read(); |
126 |
+- err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome); |
127 |
++ err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome, buffer_size); |
128 |
+ } |
129 |
+ } |
130 |
+ |
131 |
+diff --git a/modules/tga/image_loader_tga.h b/modules/tga/image_loader_tga.h |
132 |
+index 249e33411e..bbfc3fed32 100644 |
133 |
+--- a/modules/tga/image_loader_tga.h |
134 |
++++ b/modules/tga/image_loader_tga.h |
135 |
+@@ -73,7 +73,7 @@ class ImageLoaderTGA : public ImageFormatLoader { |
136 |
+ uint8_t image_descriptor; |
137 |
+ }; |
138 |
+ static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size); |
139 |
+- static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome); |
140 |
++ static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome, size_t p_output_size); |
141 |
+ |
142 |
+ public: |
143 |
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); |
144 |
|
145 |
diff --git a/dev-games/godot/godot-3.2.3.ebuild b/dev-games/godot/godot-3.2.3-r1.ebuild |
146 |
similarity index 97% |
147 |
rename from dev-games/godot/godot-3.2.3.ebuild |
148 |
rename to dev-games/godot/godot-3.2.3-r1.ebuild |
149 |
index 05980a2d..f978022f 100644 |
150 |
--- a/dev-games/godot/godot-3.2.3.ebuild |
151 |
+++ b/dev-games/godot/godot-3.2.3-r1.ebuild |
152 |
@@ -54,7 +54,10 @@ DEPEND=" |
153 |
" |
154 |
BDEPEND="virtual/pkgconfig" |
155 |
|
156 |
-PATCHES=( "${FILESDIR}"/${P}-fix-llvm-build.patch ) |
157 |
+PATCHES=( |
158 |
+ "${FILESDIR}"/${P}-fix-llvm-build.patch |
159 |
+ "${FILESDIR}"/${P}-fix-CVE-2021-26825.patch |
160 |
+) |
161 |
|
162 |
src_prepare() { |
163 |
default |