Commit 3339ea5
authored
Add allocation guards to GPU read and VRT read paths (#1196)
* Fix unbounded allocation DoS and VRT path traversal in geotiff
Two security fixes for the geotiff subpackage:
1. Add a configurable max_pixels guard to read_to_array() and all
internal read functions (_read_strips, _read_tiles, _read_cog_http).
A crafted TIFF with fabricated header dimensions could previously
trigger multi-TB allocations. The default limit is 1 billion pixels
(~4 GB for float32 single-band), overridable via max_pixels kwarg.
Fixes #1184.
2. Canonicalize VRT source filenames with os.path.realpath() after
resolving relative paths. Previously, a VRT file with "../" in
SourceFilename could read arbitrary files outside the VRT directory.
Fixes #1185.
* Fix VRT parser test failure on Windows
os.path.realpath() converts Unix-style paths to Windows paths on
Windows (e.g. /data/tile.tif becomes D:\data\tile.tif). Use
os.path.realpath() in the assertion so it matches the production
code's canonicalization on all platforms.
* Add allocation guards to GPU read and VRT read paths (#1195)
_check_dimensions() was added to CPU read paths in 521956a but missed
two allocation sites: read_geotiff_gpu() allocated from IFD dimensions
without a pixel limit, and read_vrt() allocated from VRT XML dimensions
without one. Both now call _check_dimensions() before allocating.
Adds max_pixels kwarg to open_geotiff, read_geotiff_gpu, and read_vrt
for consistency with read_to_array.1 parent 5ef4237 commit 3339ea5
3 files changed
+112
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| |||
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
219 | 224 | | |
220 | 225 | | |
221 | 226 | | |
| |||
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
228 | | - | |
| 233 | + | |
| 234 | + | |
229 | 235 | | |
230 | 236 | | |
231 | 237 | | |
232 | 238 | | |
233 | 239 | | |
234 | | - | |
| 240 | + | |
| 241 | + | |
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
239 | 246 | | |
240 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
241 | 251 | | |
242 | 252 | | |
243 | 253 | | |
| 254 | + | |
244 | 255 | | |
245 | 256 | | |
246 | 257 | | |
| |||
995 | 1006 | | |
996 | 1007 | | |
997 | 1008 | | |
998 | | - | |
| 1009 | + | |
| 1010 | + | |
999 | 1011 | | |
1000 | 1012 | | |
1001 | 1013 | | |
| |||
1018 | 1030 | | |
1019 | 1031 | | |
1020 | 1032 | | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1021 | 1036 | | |
1022 | 1037 | | |
1023 | 1038 | | |
| |||
1031 | 1046 | | |
1032 | 1047 | | |
1033 | 1048 | | |
1034 | | - | |
| 1049 | + | |
1035 | 1050 | | |
1036 | 1051 | | |
1037 | 1052 | | |
1038 | 1053 | | |
1039 | 1054 | | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1040 | 1058 | | |
1041 | 1059 | | |
1042 | 1060 | | |
| |||
1088 | 1106 | | |
1089 | 1107 | | |
1090 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
1091 | 1111 | | |
1092 | 1112 | | |
1093 | 1113 | | |
| |||
1326 | 1346 | | |
1327 | 1347 | | |
1328 | 1348 | | |
1329 | | - | |
| 1349 | + | |
| 1350 | + | |
1330 | 1351 | | |
1331 | 1352 | | |
1332 | 1353 | | |
| |||
1358 | 1379 | | |
1359 | 1380 | | |
1360 | 1381 | | |
1361 | | - | |
| 1382 | + | |
| 1383 | + | |
1362 | 1384 | | |
1363 | 1385 | | |
1364 | 1386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
| 196 | + | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
| |||
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
231 | 238 | | |
232 | 239 | | |
233 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
119 | 194 | | |
120 | 195 | | |
121 | 196 | | |
| |||
0 commit comments