diff --git a/docs/pages/tinyini/compatibility.md b/docs/pages/tinyini/compatibility.md index 4f9b839..c2f8436 100644 --- a/docs/pages/tinyini/compatibility.md +++ b/docs/pages/tinyini/compatibility.md @@ -27,13 +27,13 @@ Which ini you have decides the subpath, and `npm ls ini` shows it. `rc` pins 1.3 ## Bugs tinyini doesn't copy -| Library | Bug | tinyini | -| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| ini 1.3.5 and earlier | A `[__proto__]` section writes its keys onto `Object.prototype`, so every object in the program gets them (CVE-2020-7788). | The root and the ini subpaths drop `__proto__` sections and keys. | -| ini 1.3.8 | 2.89 KiB | 1.40 KiB | -| ini 4.1.0 to 4.1.2 | With `bracketedArray: false`, a key that repeats loses its last two characters. | tinyini/ini keeps the key, as ini 4.1.3 does. | -| ini 4.1.0 | Throws where there is no `process`, as in a browser. | tinyini/ini checks that `process` exists, as ini 4.1.1 does. | -| @one-ini/wasm | The WASM memory grows on every call and is never freed. At 4 GiB every call throws `RuntimeError: unreachable`; with 0.2.1 that takes 65,504 calls on an 800-byte file. | Keeps nothing between calls. | +| Library | Bug | tinyini | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | +| ini 1.3.5 and earlier | A `[__proto__]` section writes its keys onto `Object.prototype`, so every object in the program gets them (CVE-2020-7788). | The root and the ini subpaths drop `__proto__` sections and keys. | +| ini 1.3.8 | 2.89 KiB | 1.40 KiB | +| ini 4.1.0 to 4.1.2 | With `bracketedArray: false`, a key that repeats loses its last two characters. | tinyini/ini keeps the key, as ini 4.1.3 does. | +| ini 4.1.0 | Throws where there is no `process`, as in a browser. | tinyini/ini checks that `process` exists, as ini 4.1.1 does. | +| @one-ini/wasm | The WASM memory grows on every call and is never freed. At 4 GiB every call throws `RuntimeError: unreachable`; with 0.2.1 and 0.2.2 that takes 65,506 calls on a 6.4 KB file. | Keeps nothing between calls. | The subpaths share one core, built once per library; the root has its own smaller parser and stringifier. The sections below list each known difference from the original. @@ -60,7 +60,7 @@ The subpaths share one core, built once per library; the root has its own smalle ## @one-ini/wasm: what's different -- Memory. The WASM module's memory grows on every call, by about 48 KiB for a 1 KiB file in 0.1.1, and once it reaches 4 GiB every call throws `RuntimeError: unreachable`, for good. With 0.2.1 that takes 65,504 calls to `parse_to_uint32array` on an 800-byte file. tinyini keeps nothing between calls. +- Memory. The WASM module's memory grows on every call, by about 48 KiB for a 1 KiB file in 0.1.1, and once it reaches 4 GiB every call throws `RuntimeError: unreachable`, for good. With 0.2.1 and 0.2.2 that takes 65,506 calls to `parse_to_uint32array` on a 6.4 KB file, and about 258,000 on an 800-byte one ([reproduction](https://github.com/onmax/repros/tree/repro/one-ini-wasm-memory/one-ini-wasm-memory)). tinyini keeps nothing between calls. - Arguments of the wrong type. tinyini copies an argument in as wasm-bindgen's glue does, so a string, a `String` object, a typed array, a `Buffer` or an array gives the same result or error, and so does an array-like whose `length` is negative. An argument that doesn't act like one can differ: one whose `length` grows from one read to the next, even on a real `Uint8Array`, a typed array whose own `length` hides more bytes than the WASM module's memory has room for (it throws, tinyini doesn't), a `length` that is fractional or from 2³¹ up to 4 GiB (0.1.1 allocates that much memory, where tinyini throws `RuntimeError: unreachable` as 0.2.1 does), and a `charCodeAt` that returns something other than a UTF-16 code unit, such as a negative number. - Exports. `parse_to_json`, `parse_to_uint32array`, `version` and `TokenTypes`, as named exports and on the default export. 0.1.1 also exports wasm-bindgen's internal functions and `__wasm`, which tinyini leaves out. - `version()` and the AST's `version` say 0.2.1 or 0.1.1, the versions `editorconfig` 3 and 1 pin. 0.2.0, 0.2.2, 0.1.2 and 0.1.3 say their own version and otherwise give the same results on 20,083 fuzzed inputs each (`THEIRS= node scripts/one-ini-fuzz.ts 20000 1 one-ini`, or `one-ini-v0.1` for 0.1.x). 0.1.0 reads comments differently, trimming their text, and tinyini doesn't follow it. diff --git a/packages/tinyini/README.md b/packages/tinyini/README.md index b763267..e93fa01 100644 --- a/packages/tinyini/README.md +++ b/packages/tinyini/README.md @@ -119,13 +119,13 @@ Which ini you have decides the subpath, and `npm ls ini` shows it. `rc` pins 1.3 ### Bugs tinyini doesn't copy -| Library | Bug | tinyini | -| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| ini 1.3.5 and earlier | A `[__proto__]` section writes its keys onto `Object.prototype`, so every object in the program gets them (CVE-2020-7788). | The root and the ini subpaths drop `__proto__` sections and keys. | -| ini 1.3.8 | 2.89 KiB | 1.40 KiB | -| ini 4.1.0 to 4.1.2 | With `bracketedArray: false`, a key that repeats loses its last two characters. | tinyini/ini keeps the key, as ini 4.1.3 does. | -| ini 4.1.0 | Throws where there is no `process`, as in a browser. | tinyini/ini checks that `process` exists, as ini 4.1.1 does. | -| @one-ini/wasm | The WASM memory grows on every call and is never freed. At 4 GiB every call throws `RuntimeError: unreachable`; with 0.2.1 that takes 65,504 calls on an 800-byte file. | Keeps nothing between calls. | +| Library | Bug | tinyini | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | +| ini 1.3.5 and earlier | A `[__proto__]` section writes its keys onto `Object.prototype`, so every object in the program gets them (CVE-2020-7788). | The root and the ini subpaths drop `__proto__` sections and keys. | +| ini 1.3.8 | 2.89 KiB | 1.40 KiB | +| ini 4.1.0 to 4.1.2 | With `bracketedArray: false`, a key that repeats loses its last two characters. | tinyini/ini keeps the key, as ini 4.1.3 does. | +| ini 4.1.0 | Throws where there is no `process`, as in a browser. | tinyini/ini checks that `process` exists, as ini 4.1.1 does. | +| @one-ini/wasm | The WASM memory grows on every call and is never freed. At 4 GiB every call throws `RuntimeError: unreachable`; with 0.2.1 and 0.2.2 that takes 65,506 calls on a 6.4 KB file. | Keeps nothing between calls. | The subpaths share one core, built once per library; the root has its own smaller parser and stringifier. The details below list each known difference from the original. @@ -162,7 +162,7 @@ The subpaths share one core, built once per library; the root has its own smalle
@one-ini/wasm: what's different -- Memory. The WASM module's memory grows on every call, by about 48 KiB for a 1 KiB file in 0.1.1, and once it reaches 4 GiB every call throws `RuntimeError: unreachable`, for good. With 0.2.1 that takes 65,504 calls to `parse_to_uint32array` on an 800-byte file. tinyini keeps nothing between calls. +- Memory. The WASM module's memory grows on every call, by about 48 KiB for a 1 KiB file in 0.1.1, and once it reaches 4 GiB every call throws `RuntimeError: unreachable`, for good. With 0.2.1 and 0.2.2 that takes 65,506 calls to `parse_to_uint32array` on a 6.4 KB file, and about 258,000 on an 800-byte one ([reproduction](https://github.com/onmax/repros/tree/repro/one-ini-wasm-memory/one-ini-wasm-memory)). tinyini keeps nothing between calls. - Arguments of the wrong type. tinyini copies an argument in as wasm-bindgen's glue does, so a string, a `String` object, a typed array, a `Buffer` or an array gives the same result or error, and so does an array-like whose `length` is negative. An argument that doesn't act like one can differ: one whose `length` grows from one read to the next, even on a real `Uint8Array`, a typed array whose own `length` hides more bytes than the WASM module's memory has room for (it throws, tinyini doesn't), a `length` that is fractional or from 2³¹ up to 4 GiB (0.1.1 allocates that much memory, where tinyini throws `RuntimeError: unreachable` as 0.2.1 does), and a `charCodeAt` that returns something other than a UTF-16 code unit, such as a negative number. - Exports. `parse_to_json`, `parse_to_uint32array`, `version` and `TokenTypes`, as named exports and on the default export. 0.1.1 also exports wasm-bindgen's internal functions and `__wasm`, which tinyini leaves out. - `version()` and the AST's `version` say 0.2.1 or 0.1.1, the versions `editorconfig` 3 and 1 pin. 0.2.0, 0.2.2, 0.1.2 and 0.1.3 say their own version and otherwise give the same results on 20,083 fuzzed inputs each (`THEIRS= node scripts/one-ini-fuzz.ts 20000 1 one-ini`, or `one-ini-v0.1` for 0.1.x). 0.1.0 reads comments differently, trimming their text, and tinyini doesn't follow it. diff --git a/packages/tinyini/src/core/one-ini.ts b/packages/tinyini/src/core/one-ini.ts index 26d5d84..afa281f 100644 --- a/packages/tinyini/src/core/one-ini.ts +++ b/packages/tinyini/src/core/one-ini.ts @@ -35,6 +35,17 @@ export const TokenTypes = Object.freeze({ "4": "CommentValue", }); +/** + * A token's type, as in the `TokenTypes` enum of @one-ini/wasm, so code that + * writes `parsed[i] as TokenTypes` still compiles. + */ +export type TokenTypes = (typeof TokenTypes)[ + | "Key" + | "Value" + | "Section" + | "CommentIndicator" + | "CommentValue"]; + /** The version one-ini reports. */ export const version = (): string => (emptyValues ? "0.2.1" : "0.1.1"); diff --git a/packages/tinyini/test/types/one-ini.ts b/packages/tinyini/test/types/one-ini.ts new file mode 100644 index 0000000..de5c351 --- /dev/null +++ b/packages/tinyini/test/types/one-ini.ts @@ -0,0 +1,16 @@ +// @one-ini/wasm declares TokenTypes as an enum, which is a type as well as a +// value, and `editorconfig` 3 casts tokens to it. tsrs checks this file. +import { TokenTypes as Tokens, parse_to_uint32array } from "../../src/one-ini/index.ts"; +import { TokenTypes as Tokens01 } from "../../src/one-ini-v0.1/index.ts"; +import { same } from "./assert.ts"; + +same(true); +same(true); + +const parsed = parse_to_uint32array(new TextEncoder().encode("[*]\nindent_size = 2\n")); +switch (parsed[0] as Tokens) { + case Tokens.Section: + case Tokens.Key: + case Tokens.Value: + break; +}