@amritk/nish-x86_64-linux 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,9 +9,10 @@
9
9
  * **Decoding is strict, so that each byte string has exactly one spelling.**
10
10
  * `base64urlDecode` answers `null` for a `=` anywhere, for any character outside
11
11
  * the alphabet (whitespace included), for a length of 1 mod 4 — six bits, not a
12
- * byte — and for a final character whose unused low bits are not zero (RFC 4648
13
- * §3.5). A lenient decoder would let `AB` and `AA` both mean `00`, and a token
14
- * compared or cached by its text would then have two identities.
12
+ * byte — for a final character whose unused low bits are not zero (RFC 4648
13
+ * §3.5), and for a text longer than 2^31 - 1 bytes. A lenient decoder would let
14
+ * `AB` and `AA` both mean `00`, and a token compared or cached by its text
15
+ * would then have two identities.
15
16
  *
16
17
  * **Neither direction indexes or branches on the data.** What is encoded here
17
18
  * is usually a key, a nonce or a MAC, and a lookup table indexed by a secret
@@ -69,9 +70,15 @@ const base64urlSextetOf = (c: i32): i32 => {
69
70
  *
70
71
  * Bytes go into a bit accumulator eight at a time and come out six at a time,
71
72
  * so one index walks the input and the only branches are on how many bits are
72
- * waiting — which depends on the position, never on the bytes.
73
+ * waiting — which depends on the position, never on the bytes. An array longer
74
+ * than 2^31 - 1 bytes panics.
73
75
  */
74
76
  export const base64urlEncode = (data: u8[]): string => {
77
+ // Refused before `toI32`, which saturates a longer length under
78
+ // `--number-mode f64` and would end the loop at a prefix.
79
+ if (data.length > 2147483647) {
80
+ panic("base64urlEncode: more than 2^31 - 1 bytes")
81
+ }
75
82
  const parts: string[] = []
76
83
  let acc: i32 = 0
77
84
  let bits: i32 = 0
@@ -96,12 +103,18 @@ export const base64urlEncode = (data: u8[]): string => {
96
103
  /**
97
104
  * The bytes `text` spells in unpadded base64url, or `null` when it is not the
98
105
  * one canonical spelling of any byte string — see the module comment for the
99
- * four refusals.
106
+ * five refusals.
100
107
  *
101
108
  * The same accumulator as `base64urlEncode`, run the other way: six bits in per
102
109
  * character, eight out per byte.
103
110
  */
104
111
  export const base64urlDecode = (text: string): u8[] | null => {
112
+ // A text past 2^31 - 1 bytes is refused before `toI32`, which would
113
+ // saturate it under `--number-mode f64` and decode only a prefix: a second
114
+ // spelling of that prefix's bytes, which strictness exists to refuse.
115
+ if (text.length > 2147483647) {
116
+ return null
117
+ }
105
118
  const n: i32 = toI32(text.length)
106
119
  const tail: i32 = n & 3
107
120
  // Six bits cannot finish a byte, so a single character after the last full