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

幅or高さがImageの上限(16384px)より大きいGIFファイルを読むとアクセス違反が起きるのを修正 #1171

Merged
merged 1 commit into from Dec 27, 2023

Conversation

m4saka
Copy link
Contributor

@m4saka m4saka commented Dec 21, 2023

下記の不具合を修正しました。ご確認をお願いいたします。

不具合内容

Imageクラスで幅または高さが16384pxより大きいGIF画像を読み込もうとするとメモリアクセス違反が起きてプログラムがクラッシュする。

不具合原因

Imageクラスの幅・高さは16384pxが上限(Image::MaxWidthImage::MaxHeight)なので、それより大きいサイズで生成しようとするとImageクラスのコンストラクタで0px扱いになる。

しかし、GIFDecoder::decode内の下記では指定した幅・高さで初期化されていることを前提にポインタで操作していたため、Imageの幅または高さが0px扱いになった場合にはポインタが範囲外のアドレスを参照してアクセス違反が生じていた。

Image image{ width, height };
Color* pDst = image.data();
for (size_t y = 0; y < height; ++y)
{
size_t srcOffset = y * width;
size_t dstOffset = (y + offset_y) * gif->SWidth + offset_x;
for (size_t x = 0; x < width; ++x)
{
const uint8 index = frame->RasterBits[srcOffset];
*(pDst + dstOffset) = palette[index];
++srcOffset;
++dstOffset;
}
}

修正内容

Image::operator bool()がfalseを返す(=画像が空である)場合はデコードを止めるように修正。
また、本件と直接関係はないがDGifCloseFileに漏れがあった箇所も修正。

@Reputeless Reputeless merged commit 6c63dfb into Siv3D:v6_develop Dec 27, 2023
2 checks passed
@Reputeless
Copy link
Member

Merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants