@@ -120,14 +120,14 @@ bool BitmapImage::parseDibHeader(const ResourceIcon &icon, struct BitmapInformat
120
120
121
121
std::size_t offset = 0 ;
122
122
res.size = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.size );
123
- res.width = *reinterpret_cast <int32_t *>(&bytes.data ()[offset]); offset += sizeof (res.width );
124
- res.height = *reinterpret_cast <int32_t *>(&bytes.data ()[offset]); offset += sizeof (res.height );
123
+ res.width = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.width );
124
+ res.height = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.height );
125
125
res.planes = *reinterpret_cast <uint16_t *>(&bytes.data ()[offset]); offset += sizeof (res.planes );
126
126
res.bitCount = *reinterpret_cast <uint16_t *>(&bytes.data ()[offset]); offset += sizeof (res.bitCount );
127
127
res.compression = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.compression );
128
128
res.bitmapSize = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.bitmapSize );
129
- res.horizontalRes = *reinterpret_cast <int32_t *>(&bytes.data ()[offset]); offset += sizeof (res.horizontalRes );
130
- res.verticalRes = *reinterpret_cast <int32_t *>(&bytes.data ()[offset]); offset += sizeof (res.verticalRes );
129
+ res.horizontalRes = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.horizontalRes );
130
+ res.verticalRes = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.verticalRes );
131
131
res.colorsUsed = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.colorsUsed );
132
132
res.colorImportant = *reinterpret_cast <uint32_t *>(&bytes.data ()[offset]); offset += sizeof (res.colorImportant );
133
133
@@ -147,7 +147,8 @@ bool BitmapImage::parseDibHeader(const ResourceIcon &icon, struct BitmapInformat
147
147
}
148
148
149
149
if (res.size != res.headerSize () || res.planes != 1 || res.compression != 0 ||
150
- res.width * 2 != res.height || res.width > 512 || res.bitCount > 32 )
150
+ res.width * 2 != res.height || res.width > 512 || res.height > 1024 ||
151
+ res.bitCount > 32 )
151
152
{
152
153
return false ;
153
154
}
@@ -209,6 +210,11 @@ bool BitmapImage::parseDib1Data(const ResourceIcon &icon, const struct BitmapInf
209
210
{
210
211
for (std::size_t i = 0 ; i < 8 ; i++)
211
212
{
213
+ if (bytes.size () <= offset)
214
+ {
215
+ return false ;
216
+ }
217
+
212
218
auto bit = (bytes[offset] & (0x01 << (7 - i)));
213
219
auto index = (bit == 0 ) ? 0 : 1 ;
214
220
row.push_back (palette[index]);
@@ -223,6 +229,11 @@ bool BitmapImage::parseDib1Data(const ResourceIcon &icon, const struct BitmapInf
223
229
{
224
230
for (std::size_t i = 0 ; i < rest; i++)
225
231
{
232
+ if (bytes.size () <= offset)
233
+ {
234
+ return false ;
235
+ }
236
+
226
237
auto index = !!(bytes[offset] & (0x01 << (7 - i)));
227
238
row.push_back (palette[index]);
228
239
}
@@ -289,13 +300,23 @@ bool BitmapImage::parseDib4Data(const ResourceIcon &icon, const struct BitmapInf
289
300
290
301
for (std::size_t j = 0 ; j < nColumns / 2 ; j++)
291
302
{
303
+ if (bytes.size () <= offset)
304
+ {
305
+ return false ;
306
+ }
307
+
292
308
row.push_back (palette[bytes[offset] >> 4 ]);
293
309
row.push_back (palette[bytes[offset] & 0x0F ]);
294
310
offset++;
295
311
}
296
312
297
313
if (nColumns % 2 )
298
314
{
315
+ if (bytes.size () <= offset)
316
+ {
317
+ return false ;
318
+ }
319
+
299
320
row.push_back (palette[bytes[offset] >> 4 ]);
300
321
offset++;
301
322
}
@@ -360,6 +381,11 @@ bool BitmapImage::parseDib8Data(const ResourceIcon &icon, const struct BitmapInf
360
381
361
382
for (std::size_t j = 0 ; j < nColumns; j++)
362
383
{
384
+ if (bytes.size () <= offset)
385
+ {
386
+ return false ;
387
+ }
388
+
363
389
row.push_back (palette[bytes[offset]]);
364
390
offset += bytesPP;
365
391
}
@@ -409,6 +435,11 @@ bool BitmapImage::parseDib24Data(const ResourceIcon &icon, const struct BitmapIn
409
435
410
436
for (std::size_t j = 0 ; j < nColumns; j++)
411
437
{
438
+ if (bytes.size () <= (offset+2 ))
439
+ {
440
+ return false ;
441
+ }
442
+
412
443
row.emplace_back (bytes[offset + 2 ], bytes[offset + 1 ], bytes[offset], 0xFF );
413
444
offset += bytesPP;
414
445
}
@@ -457,6 +488,11 @@ bool BitmapImage::parseDib32Data(const ResourceIcon &icon, const struct BitmapIn
457
488
458
489
for (std::size_t j = 0 ; j < nColumns; j++)
459
490
{
491
+ if (bytes.size () <= (offset+3 ))
492
+ {
493
+ return false ;
494
+ }
495
+
460
496
row.emplace_back (bytes[offset + 2 ], bytes[offset + 1 ], bytes[offset], bytes[offset + 3 ]);
461
497
offset += bytesPP;
462
498
}
@@ -488,6 +524,11 @@ bool BitmapImage::parseDibPalette(const ResourceIcon &icon, std::vector<struct B
488
524
489
525
for (std::uint32_t i = 0 ; i < nBytes; i += 4 )
490
526
{
527
+ if (bytes.size () <= (i+3 ))
528
+ {
529
+ return false ;
530
+ }
531
+
491
532
palette.emplace_back (bytes[i + 2 ], bytes[i + 1 ], bytes[i], bytes[i + 3 ]);
492
533
}
493
534
0 commit comments