Commit eb3ab0d
committed
Make DynArray support objects larger than 1 gigabyte
The expression ``const int newAllocated = cap * 2;`` easily causes
overflow, as soon as the input is 1.0 GiB. This goes unnoticed because
release builds of tinyxml2 do not have active assertions.
The change in commit 9.0.0-20-g8fd6cc6 did not do anything useful;
the signed multiplication overflow (and thus undefined behavior)
still occurs.
Using ``int`` in this class is really archaic, because it limits the
class to a gigabyte even on 64-bit platforms.
The multiplication overflow check also needs to include sizeof(T),
otherwise you can run into unsigned multiplication overflow (defined,
but undesirable) in the memcpy() call.
testcase:
int main()
{
tinyxml2::XMLDocument doc;
doc.InsertEndChild(doc.NewDeclaration());
auto root = doc.NewElement("root");
size_t sz = 0x80000001;
auto blank = new char[sz];
memset(blank, ' ', sz);
blank[sz-1]='\0';
root->SetText(blank);
doc.InsertEndChild(root);
tinyxml2::XMLPrinter printer(nullptr);
doc.Print(&printer);
}1 parent 3a893e5 commit eb3ab0d
2 files changed
Lines changed: 33 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2221 | 2221 | | |
2222 | 2222 | | |
2223 | 2223 | | |
2224 | | - | |
| 2224 | + | |
2225 | 2225 | | |
2226 | 2226 | | |
2227 | 2227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 230 | + | |
| 231 | + | |
233 | 232 | | |
234 | 233 | | |
235 | 234 | | |
| |||
242 | 241 | | |
243 | 242 | | |
244 | 243 | | |
245 | | - | |
| 244 | + | |
246 | 245 | | |
247 | 246 | | |
248 | 247 | | |
| |||
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
254 | | - | |
255 | | - | |
| 253 | + | |
| 254 | + | |
256 | 255 | | |
257 | 256 | | |
258 | 257 | | |
259 | | - | |
260 | | - | |
| 258 | + | |
| 259 | + | |
261 | 260 | | |
262 | 261 | | |
263 | 262 | | |
| |||
266 | 265 | | |
267 | 266 | | |
268 | 267 | | |
269 | | - | |
| 268 | + | |
270 | 269 | | |
271 | 270 | | |
272 | 271 | | |
273 | 272 | | |
274 | | - | |
| 273 | + | |
275 | 274 | | |
276 | 275 | | |
277 | 276 | | |
278 | 277 | | |
279 | | - | |
280 | | - | |
| 278 | + | |
| 279 | + | |
281 | 280 | | |
282 | 281 | | |
283 | 282 | | |
| |||
297 | 296 | | |
298 | 297 | | |
299 | 298 | | |
300 | | - | |
| 299 | + | |
301 | 300 | | |
302 | 301 | | |
303 | | - | |
304 | | - | |
305 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
306 | 305 | | |
307 | | - | |
| 306 | + | |
308 | 307 | | |
309 | 308 | | |
310 | 309 | | |
| |||
314 | 313 | | |
315 | 314 | | |
316 | 315 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
320 | 319 | | |
321 | 320 | | |
322 | 321 | | |
| |||
330 | 329 | | |
331 | 330 | | |
332 | 331 | | |
333 | | - | |
| 332 | + | |
334 | 333 | | |
335 | 334 | | |
336 | 335 | | |
| |||
340 | 339 | | |
341 | 340 | | |
342 | 341 | | |
343 | | - | |
| 342 | + | |
344 | 343 | | |
345 | 344 | | |
346 | 345 | | |
| |||
362 | 361 | | |
363 | 362 | | |
364 | 363 | | |
365 | | - | |
| 364 | + | |
366 | 365 | | |
367 | 366 | | |
368 | | - | |
| 367 | + | |
369 | 368 | | |
370 | 369 | | |
371 | 370 | | |
| |||
376 | 375 | | |
377 | 376 | | |
378 | 377 | | |
379 | | - | |
| 378 | + | |
380 | 379 | | |
381 | 380 | | |
382 | 381 | | |
| |||
417 | 416 | | |
418 | 417 | | |
419 | 418 | | |
420 | | - | |
| 419 | + | |
421 | 420 | | |
422 | 421 | | |
423 | 422 | | |
| |||
448 | 447 | | |
449 | 448 | | |
450 | 449 | | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
455 | 454 | | |
456 | 455 | | |
457 | 456 | | |
| |||
1981 | 1980 | | |
1982 | 1981 | | |
1983 | 1982 | | |
1984 | | - | |
| 1983 | + | |
1985 | 1984 | | |
1986 | 1985 | | |
1987 | 1986 | | |
1988 | | - | |
| 1987 | + | |
1989 | 1988 | | |
1990 | 1989 | | |
1991 | 1990 | | |
| |||
0 commit comments