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

Aperta Adatta ai principianti
#7,383 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@helmipradita ci sta già lavorando.

Dal 7/11/2026.

  • #7388 di @helmipradita — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
deno, typescript
Ambito
backend, devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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/

Lingua principale
TypeScript
Stelle
3.6k
Fork
713
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di denoland/std

Tutte le issue di denoland/std

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.