|
1 | 1 | /* -*-C-*-
|
2 | 2 | ******************************************************************************
|
3 |
| - * File: matrix.h (Formerly matrix.h) |
| 3 | + * File: matrix.h |
4 | 4 | * Description: Generic 2-d array/matrix and banded triangular matrix class.
|
5 | 5 | * Author: Ray Smith
|
6 | 6 | * TODO(rays) Separate from ratings matrix, which it also contains:
|
|
10 | 10 | * Author: Mark Seaman, OCR Technology
|
11 | 11 | * Created: Wed May 16 13:22:06 1990
|
12 | 12 | * Modified: Tue Mar 19 16:00:20 1991 (Mark Seaman) marks@hpgrlt
|
13 |
| - * Language: C |
14 |
| - * Package: N/A |
15 |
| - * Status: Experimental (Do Not Distribute) |
16 | 13 | *
|
17 | 14 | * (c) Copyright 1990, Hewlett-Packard Company.
|
18 | 15 | ** Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -492,13 +489,19 @@ class GENERIC_2D_ARRAY {
|
492 | 489 | ReverseN(&size1, sizeof(size1));
|
493 | 490 | ReverseN(&size2, sizeof(size2));
|
494 | 491 | }
|
| 492 | + // Arbitrarily limit the number of elements to protect against bad data. |
| 493 | + if (size1 > UINT16_MAX) return false; |
| 494 | + if (size2 > UINT16_MAX) return false; |
495 | 495 | Resize(size1, size2, empty_);
|
496 | 496 | return true;
|
497 | 497 | }
|
498 | 498 | bool DeSerializeSize(tesseract::TFile* fp) {
|
499 | 499 | int32_t size1, size2;
|
500 | 500 | if (fp->FReadEndian(&size1, sizeof(size1), 1) != 1) return false;
|
501 | 501 | if (fp->FReadEndian(&size2, sizeof(size2), 1) != 1) return false;
|
| 502 | + // Arbitrarily limit the number of elements to protect against bad data. |
| 503 | + if (size1 > UINT16_MAX) return false; |
| 504 | + if (size2 > UINT16_MAX) return false; |
502 | 505 | Resize(size1, size2, empty_);
|
503 | 506 | return true;
|
504 | 507 | }
|
|
0 commit comments