Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 1 | From 51558511bdbbcffdce534db21dbaf5d54b31638a Mon Sep 17 00:00:00 2001 |
| 2 | From: Even Rouault <even.rouault@spatialys.com> |
| 3 | Date: Thu, 1 Feb 2024 11:38:14 +0000 |
| 4 | Subject: [PATCH] TIFFReadRGBAStrip/TIFFReadRGBATile: add more validation of |
| 5 | col/row (fixes #622) |
| 6 | |
| 7 | CVE: CVE-2023-52356 |
| 8 | Upstream-Status: Backport [https://gitlab.com/libtiff/libtiff/-/commit/51558511bdbbcffdce534db21dbaf5d54b31638a] |
| 9 | |
| 10 | Signed-off-by: Yogita Urade <yogita.urade@windriver.com> |
| 11 | --- |
| 12 | libtiff/tif_getimage.c | 15 +++++++++++++++ |
| 13 | 1 file changed, 15 insertions(+) |
| 14 | |
| 15 | diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c |
| 16 | index 41f7dfd..9cd6eee 100644 |
| 17 | --- a/libtiff/tif_getimage.c |
| 18 | +++ b/libtiff/tif_getimage.c |
| 19 | @@ -3224,6 +3224,13 @@ int TIFFReadRGBAStripExt(TIFF *tif, uint32_t row, uint32_t *raster, |
| 20 | if (TIFFRGBAImageOK(tif, emsg) && |
| 21 | TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg)) |
| 22 | { |
| 23 | + if (row >= img.height) |
| 24 | + { |
| 25 | + TIFFErrorExtR(tif, TIFFFileName(tif), |
| 26 | + "Invalid row passed to TIFFReadRGBAStrip()."); |
| 27 | + TIFFRGBAImageEnd(&img); |
| 28 | + return (0); |
| 29 | + } |
| 30 | |
| 31 | img.row_offset = row; |
| 32 | img.col_offset = 0; |
| 33 | @@ -3301,6 +3308,14 @@ int TIFFReadRGBATileExt(TIFF *tif, uint32_t col, uint32_t row, uint32_t *raster, |
| 34 | return (0); |
| 35 | } |
| 36 | |
| 37 | + if (col >= img.width || row >= img.height) |
| 38 | + { |
| 39 | + TIFFErrorExtR(tif, TIFFFileName(tif), |
| 40 | + "Invalid row/col passed to TIFFReadRGBATile()."); |
| 41 | + TIFFRGBAImageEnd(&img); |
| 42 | + return (0); |
| 43 | + } |
| 44 | + |
| 45 | /* |
| 46 | * The TIFFRGBAImageGet() function doesn't allow us to get off the |
| 47 | * edge of the image, even to fill an otherwise valid tile. So we |
| 48 | -- |
| 49 | 2.40.0 |