Signed overflow to heap out of bounds write in dynamic IO context (appendDynamic)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 74/100
調査の方向性
src/gd_io_dp.cから始め、特に359行目付近のappendDynamic()と、報告に記載されているdynamicSeek()の動作を確認してください。bytesNeededの計算方法とバッファを拡張するかどうかの判断方法を調べてから、UBSanまたはASanで再現コードを実行してください。INT_MAXの近くへのシークと16バイトの書き込みで、オーバーフローやバッファ外への書き込みが発生しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
appendDynamic() in the dynamic IO context has a signed integer overflow that leads to a heap out of bounds write.
Location: src/gd_io_dp.c:359. bytesNeeded = dp->pos + size overflows signed int when pos is near INT_MAX. The grow check at line 361 (bytesNeeded > dp->realSize) then passes with a negative value, the realloc is skipped, and line 383 does memcpy(tmp + dp->pos, src, size) about 2 GB past a small heap buffer.
Root cause: dynamicSeek() (lines 177-221) only grows the buffer once (realSize * 2) when seeking past EOF, then happily sets pos and logicalSize to the huge value.
Reproduce (needs gdNewDynamicCtx(1024, NULL), seek to 2147483640, write 16 bytes):
gdIOCtx *ctx = gdNewDynamicCtx(1024, NULL);
ctx->seek(ctx, 2147483640);
ctx->putBuf(ctx, buf, 16);
Confirmed: UBSan reports signed integer overflow: 16 + 2147483640 at gd_io_dp.c:359. An ASan-only build segfaults on WRITE in memcpy from appendDynamic (gd_io_dp.c:383) via dynamicPutbuf.
To be clear about the scope: this is NOT reachable from a crafted image file through libgd's own decoders or encoders. Libgd's own seeks on a dynamic context are small constants (BMP header patch-ups) or image derived GD2 chunk offsets that cannot approach INT_MAX without a multi-GB image already in memory. It needs a caller that seeks a dynamic context from untrusted offsets.
Severity is low. The write offset is always about 2 GB past the buffer, so in practice it crashes rather than giving controlled heap corruption. appendDynamic should check pos > INT_MAX - size before adding. Tested against libgd 2.3.3.
- 主要言語
- C
- スター
- 985
- フォーク
- 289
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
libgd/libgd のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
libgd: Uninitialized Stack Read in gdImageScaleBicubicFixed Leading to Out-of-bounds Pixel Accessオープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
libsndfile/libsndfile#1239 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
CommonLoon102/restunts-bb11#101 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100