Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image decompression may cause buffer overflow #16926

Open
qiuguohua opened this issue Apr 24, 2024 · 0 comments
Open

Image decompression may cause buffer overflow #16926

qiuguohua opened this issue Apr 24, 2024 · 0 comments
Assignees
Labels
Bug Needs Triage Needs to be assigned by the team

Comments

@qiuguohua
Copy link
Contributor

qiuguohua commented Apr 24, 2024

Cocos Creator version

all

System information

native

Issue description

The vulnerable Image::initWithJpgData function in file Image.cpp (https://github.com/cocos/cocos-engine/blob/v3.8.4/native/cocos/platform/Image.cpp#L518)
is used to decompress jpegs and create a raw bitmap version of the image.

In Image::initWithJpgData, the values for cinfo.output_width and cinfo.output_height are retrieved directly from a jpeg file's header.

cinfo.output_width and cinfo.output_height can be manipulated by editing the header of the jpeg file being processed. They are two bytes each in the image's header so their values can
range from 0x0000 to 0xFFFF. These variables are multiplied with cinfo.output_components.

When these three values are multiplied together they can exceed the limit of a 32-bit unsigned integer, leading to an integer overflow vulnerability. This product is used to set the
size of the _data buffer, which will store the decompressed jpeg (https://github.com/cocos/cocos-engine/blob/v3.8.4/native/cocos/platform/Image.cpp#L574).
When the sizing arguments overflow, the buffer becomes too small to store the decompressed data.

The program writes the decompressed image to the buffer using the jpeg_read_scanlines function. The function ends up writing to out-of-bounds memory due to the buffer’s small size (https://github.com/cocos/cocos-engine/blob/v3.8.4/native/cocos/platform/Image.cpp#L582).
This causes data in memory adjacent to the buffer to be overwritten.

An attacker is in control of the image's height, width, and contents. This allows an attacker to craft an exploit to overwrite data in memory with data they control.

Relevant error log output

No response

Steps to reproduce

No

Minimal reproduction project

No response

@qiuguohua qiuguohua added Bug Needs Triage Needs to be assigned by the team labels Apr 24, 2024
@qiuguohua qiuguohua self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

1 participant