@std/encoding: decodeAscii85 corrupts delimited data ending in "<", decodeVarint32 reads past the end of the buffer

オープン 初心者向け
#7,383 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@helmipradita がすでに取り組んでいます。

2026年11月7日 から。

  • #7388 @helmipradita による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
deno, typescript
領域
backend, devtools

調査の方向性

Read encoding/ascii85.ts and encoding/varint.ts, focusing on the delimiter removal and the decodeVarint32 loop and bounds checks described in the issue. Run the reproduction with Deno, then add or run focused tests for both cases. Done means delimited ASCII85 round trips when the payload ends in <, and malformed, truncated, or overflowing 32-bit varints throw RangeError.

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

  1. decodeAscii85 does not round trip encodeAscii85(data, { delimiter: true }) when the encoded payload ends in <: the last byte comes back wrong.
  2. decodeVarint32 accepts truncated input and returns an offset past the end of the buffer, reads a 6th byte, and returns values above 0xffffffff. decodeVarint throws a RangeError on the same truncated input.

Steps to Reproduce

import { decodeAscii85, encodeAscii85 } from "jsr:@std/[email protected]/ascii85";
import { decodeVarint, decodeVarint32 } from "jsr:@std/[email protected]/varint";

const encoded = encodeAscii85(new Uint8Array([0xc6, 0x91, 0xeb, 0x81]), { delimiter: true });
console.log(encoded, decodeAscii85(encoded));
console.log(decodeVarint32(new Uint8Array([0x80])));
console.log(decodeVarint32(new Uint8Array([0xff, 0xff])));
console.log(decodeVarint32(new Uint8Array([0x80, 0x80, 0x80, 0x80, 0x80, 0x01])));
console.log(decodeVarint32(new Uint8Array([0xff, 0xff, 0xff, 0xff, 0x7f])));
try { console.log(decodeVarint(new Uint8Array([0x80]))); } catch (e) { console.log(String(e)); }

deno run repro.ts

Expected behavior

The first line ends with Uint8Array(4) [ 198, 145, 235, 129 ]. The four decodeVarint32 calls throw RangeError like decodeVarint (truncated, 6 bytes, and above 32 bits).

Actual behavior

<~`f]S<~> Uint8Array(4) [ 198, 145, 235, 131 ]
[ 0, 2 ]
[ 16383, 3 ]
[ 34359738368, 6 ]
[ 34359738367, 5 ]
RangeError: Cannot decode the varint input: Malformed or overflow varint

In encoding/ascii85.ts, replaceAll(/(<~|~>)/g, "") matches the payload's trailing < plus the ~ of the closing ~>, leaving a stray >. In encoding/varint.ts, decodeVarint32 loops with i <= Math.min(buf.length, offset + MaxVarintLen32) instead of <, and never checks the 32-bit bound.

Environment

  • OS: Debian 12 (x86_64)
  • deno version: 2.9.8
  • std version: @std/encoding 1.0.11, also main at f834d02

Credit: https://ucsbplse.github.io/

主要言語
TypeScript
スター
3.6k
フォーク
713
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

denoland/std のほかの issue

denoland/std の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。