Commit de02b52
authored
Fix Coverity TAINTED_SCALAR in ImageBMP::read (#997)
Resolves: CID-51802
BmpUtils::load_bmp_image[_8u] sets width_/height_ from the BMP file
header and may then return false (e.g. when bounds checks fail or data
read fails). The previous code called pixels_.resize(size(), 0) and
copy_raw_data(data.get()) unconditionally, which means:
- On the error path where width_/height_ were set from the file but
data was not allocated (nullptr), copy_raw_data would perform
std::copy from a null pointer — undefined behaviour.
- A malformed BMP with very large dimensions could trigger an
enormous allocation before the error was returned.
Fix: guard pixels_.resize() and copy_raw_data() with if (!error) in
both ImageBMP<T>::read (generic template) and the ImageBMP<uint8_t>
specialization. The success path is unaffected; load_bmp_image's
internal bounds checks (height/pitch <= 65536) ensure the dimensions
are safe when !error.1 parent 84f3174 commit de02b52
1 file changed
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
206 | | - | |
207 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
0 commit comments