提交 06e7107e 编写于 作者: Y Yilu Mao 提交者: YiluMao

Fix potential overflow issue

"tjAlloc()" uses "malloc()" which takes a "size_t" number of bytes (an
unsigned integer).

However,"tjAlloc()" itself takes the number of bytes as a signed integer.
So the width * height * tjPixelSize[pixelfmt] may overflow and become a
negative integer.

Fix by checking it and change to use malloc directly.

Change-Id: Ia69e37f66c6674c1201c06df8e35d8877ae081cd
Signed-off-by: NYilu Mao <yilu.myl@alibaba-inc.com>
上级 04af12ab
......@@ -124,8 +124,15 @@ int tjpeg2rgb(unsigned char *jpeg_buffer, int jpeg_size,
}
LOG("width: %d, height: %d", width, height);
flags |= 0;
*rgb_buffer = (unsigned char *)tjAlloc(width * height *
tjPixelSize[pixelfmt]);
if ((unsigned long long)width * height * tjPixelSize[pixelfmt] >
(unsigned long long)((size_t)-1)) {
LOGE(TAG, "Image is too large!!!");
goto finish;
}
*rgb_buffer = (unsigned char *)malloc(sizeof(unsigned char) * width * height *
tjPixelSize[pixelfmt]);
if ((*rgb_buffer) == NULL) {
LOGE(TAG, "allocating uncompressed image buffer");
goto finish;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册