Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/pages/tinyini/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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=<path> 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.
Expand Down
16 changes: 8 additions & 8 deletions packages/tinyini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -162,7 +162,7 @@ The subpaths share one core, built once per library; the root has its own smalle
<details>
<summary>@one-ini/wasm: what's different</summary>

- 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=<path> 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.
Expand Down
11 changes: 11 additions & 0 deletions packages/tinyini/src/core/one-ini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
16 changes: 16 additions & 0 deletions packages/tinyini/test/types/one-ini.ts
Original file line number Diff line number Diff line change
@@ -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<Tokens, 0 | 1 | 2 | 3 | 4>(true);
same<Tokens01, 0 | 1 | 2 | 3 | 4>(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;
}
Loading