
HReddy118194 (Community Member) asked a question.
Errors are on lines:
- size_t pixelCount = width * height;
- size_t componentCount = pixelCount << 2;
- size_t bytesPerRow = width << 2;
where size_t is unsigned long long.
PLRGBImageRef _Nullable CreateDocProcessingEngine(uint8_t *_Nonnull ioBytes,
int inWidth, int inHeight)
try
{
size_t width = static_cast<size_t>(inWidth);
size_t height = static_cast<size_t>(inHeight);
size_t pixelCount = width * height;
if (0 == (size_t(ioBytes) % alignof(uint32_t)))
{
uint32_t *pixels = reinterpret_cast<uint32_t *>(ioBytes);
for (size_t i = 0; i < pixelCount; i++)
{
if (0 == pixels[i])
{
pixels[i] = 0xFFFFFFFF;
}
}
}
else
{
size_t componentCount = pixelCount << 2;
uint32_t blackPixel = 0;
for (size_t i = 0; i < componentCount; i += 4)
{
if (0 == memcmp(&ioBytes[i], &blackPixel, 4))
{
memset(&ioBytes[i], 0xFF, 4);
}
}
}
size_t bytesPerRow = width << 2;
unique_ptr<RGBXImage> rgbaImage(new RGBXImage(ioBytes,
{height, width, bytesPerRow}, 0, 0));
RGBImage *rgbImage = rgbaImage->ToRGB();
return rgbImage;
}
.png)
Please see the answer to your other question, here: https://community.veracode.com/s/question/0D5Uf00000BfoG1KAJ/i-am-getting-an-integer-overflow-issue-for-the-following-code-please-help-me-fix-this-error