-
Notifications
You must be signed in to change notification settings - Fork 690
fix(softimage): Prevent buffer overruns from corrupt RLE #5142
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,12 @@ SoftimageInput::open(const std::string& name, ImageSpec& spec) | |
| close(); | ||
| return false; | ||
| } | ||
| // Some validity checking | ||
| if (curPacket.size != 8 && curPacket.size != 16) { | ||
| errorfmt("Unsupported bits per channel {}", curPacket.size); | ||
| close(); | ||
| return false; | ||
| } | ||
| m_channel_packets.push_back(curPacket); | ||
|
|
||
| // Add the number of channels in this packet to nchannels | ||
|
|
@@ -135,6 +141,12 @@ SoftimageInput::open(const std::string& name, ImageSpec& spec) | |
| // Set the details in the ImageSpec | ||
| m_spec = ImageSpec(m_pic_header.width, m_pic_header.height, nchannels, | ||
| chanType); | ||
|
|
||
| if (!check_open(m_spec, { 0, 65535, 0, 65535, 0, 1, 0, 4 })) { | ||
| close(); | ||
| return false; | ||
| } | ||
|
|
||
| m_spec.attribute("BitsPerSample", (int)curPacket.size); | ||
|
|
||
| m_spec.attribute("softimage:compression", Strutil::join(encodings, ",")); | ||
|
|
@@ -333,6 +345,10 @@ SoftimageInput::read_pixels_pure_run_length( | |
| if (fread(&curCount, 1, 1, m_fd) != 1) | ||
| return false; | ||
|
|
||
| // Clamp to avoid writing past the end of the scanline buffer | ||
| if (linePixelCount + curCount > m_pic_header.width) | ||
| curCount = m_pic_header.width - linePixelCount; | ||
|
|
||
| if (data) { | ||
| // data pointer is set so we're supposed to write data there | ||
| size_t pixelSize = pixelChannelSize * channels.size(); | ||
|
Comment on lines
+350
to
354
|
||
|
|
@@ -456,6 +472,10 @@ SoftimageInput::read_pixels_mixed_run_length( | |
| longCount = curCount - 127; | ||
| } | ||
|
|
||
| // Clamp to avoid writing past the end of the scanline buffer | ||
| if (linePixelCount + longCount > m_pic_header.width) | ||
| longCount = m_pic_header.width - linePixelCount; | ||
|
|
||
|
Comment on lines
474
to
+478
|
||
| if (data) { | ||
| // data pointer is set so we're supposed to write data there | ||
| size_t pixelSize = pixelChannelSize * channels.size(); | ||
|
Comment on lines
+475
to
481
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
read_pixels_pure_run_length, a corrupt file can encode a run length of 0. In that caselinePixelCountnever advances and thewhile (linePixelCount < width)loop can become infinite (DoS/hang). Consider treating a 0 count as corruption and returning false (or otherwise guaranteeing forward progress) before applying the clamp.