@amritk/nish-aarch64-linux 0.49.1 → 0.51.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.
- package/INSTALL.md +1 -1
- package/bin/nish +0 -0
- package/docs/AI.md +237 -160
- package/package.json +1 -1
- package/runtime/gfx/nish-gfx.h +373 -61
- package/runtime/nish.d.ts +94 -11
- package/runtime/nish.h +5 -0
- package/runtime/runtime-host.c +21 -5
- package/std/README.md +14 -11
- package/std/base64.ts +74 -35
- package/std/bytes.ts +207 -97
- package/std/cli-args.ts +150 -107
- package/std/compress/checksum.ts +68 -10
- package/std/compress/deflate.ts +213 -115
- package/std/compress/gzip.ts +124 -49
- package/std/compress/zlib.ts +57 -15
- package/std/crypto/aes.ts +51 -9
- package/std/crypto/base64url.ts +93 -66
- package/std/crypto/bcrypt.ts +25 -21
- package/std/crypto/ed25519.ts +12 -10
- package/std/crypto/hkdf.ts +405 -283
- package/std/crypto/hmac.ts +484 -149
- package/std/crypto/jwt.ts +51 -40
- package/std/crypto/p256.ts +14 -19
- package/std/crypto/pki-roots.ts +35 -12
- package/std/crypto/pki.ts +43 -55
- package/std/crypto/rsa-sign.ts +1635 -0
- package/std/crypto/rsa.ts +26 -4
- package/std/crypto/sha256.ts +212 -90
- package/std/crypto/sha512.ts +135 -49
- package/std/crypto/x25519.ts +12 -11
- package/std/crypto/x509.ts +164 -40
- package/std/gpu/sys.ts +490 -0
- package/std/json-equal.ts +33 -18
- package/std/json-format.ts +39 -8
- package/std/json-number.ts +15 -3
- package/std/json-tokenizer.ts +4 -3
- package/std/json-typed.ts +12 -6
- package/std/json-value.ts +236 -119
- package/std/json.ts +81 -46
- package/std/net/buffer-pool.ts +25 -14
- package/std/net/dns-config.ts +18 -5
- package/std/net/dns-message.ts +60 -27
- package/std/net/dns-resolver.ts +35 -16
- package/std/net/dns.ts +3 -2
- package/std/net/fetch.ts +224 -61
- package/std/net/handler.ts +189 -88
- package/std/net/hpack.ts +216 -103
- package/std/net/http-compress.ts +104 -42
- package/std/net/http-fields.ts +327 -31
- package/std/net/http-server.ts +326 -24
- package/std/net/http1-client-codec.ts +159 -55
- package/std/net/http1-codec.ts +427 -237
- package/std/net/http1-server.ts +220 -38
- package/std/net/http2-cleartext.ts +10 -4
- package/std/net/http2-frame.ts +2 -2
- package/std/net/http2-tls.ts +3 -3
- package/std/net/http2.ts +69 -15
- package/std/net/http3-frame.ts +11 -14
- package/std/net/http3-server.ts +139 -60
- package/std/net/http3.ts +140 -79
- package/std/net/multipart.ts +592 -0
- package/std/net/outbound.ts +24 -8
- package/std/net/postgres-async.ts +97 -64
- package/std/net/postgres-carrier.ts +28 -4
- package/std/net/postgres.ts +166 -65
- package/std/net/prefork.ts +86 -5
- package/std/net/protobuf.ts +6 -2
- package/std/net/qpack.ts +147 -40
- package/std/net/quic-conn-ack.ts +27 -7
- package/std/net/quic-conn-cid.ts +13 -7
- package/std/net/quic-datagram.ts +6 -5
- package/std/net/quic-frame.ts +67 -23
- package/std/net/quic-listener.ts +61 -39
- package/std/net/quic-packet.ts +91 -50
- package/std/net/quic-recovery.ts +11 -9
- package/std/net/quic-stream.ts +36 -27
- package/std/net/quic.ts +84 -54
- package/std/net/router.ts +136 -24
- package/std/net/serve.ts +59 -5
- package/std/net/static.ts +86 -36
- package/std/net/tls/client.ts +81 -34
- package/std/net/tls/codec.ts +3 -4
- package/std/net/tls/record.ts +80 -35
- package/std/net/tls/schedule.ts +339 -149
- package/std/net/tls/ticket.ts +6 -5
- package/std/net/tls-tcp.ts +69 -30
- package/std/net/tls.ts +194 -50
- package/std/net/upstream.ts +83 -38
- package/std/net/url.ts +170 -94
- package/std/net/websocket.ts +19 -20
- package/std/net/webtransport.ts +123 -33
- package/std/raster.ts +12 -2
- package/std/regex.ts +600 -388
- package/std/sqlite.ts +37 -19
- package/std/sync/ring.ts +232 -115
- package/std/sync/shm.ts +11 -4
- package/std/temporal.ts +232 -133
- package/std/term-io.ts +12 -6
- package/std/term-pixels.ts +176 -24
- package/std/term-rate.ts +8 -3
- package/std/term.ts +4 -4
- package/std/text.ts +38 -16
- package/std/yaml-json.ts +238 -106
- package/std/yaml-lines.ts +47 -27
- package/std/yaml-write.ts +58 -24
- package/std/yaml.ts +808 -395
package/std/net/http-compress.ts
CHANGED
|
@@ -80,7 +80,12 @@
|
|
|
80
80
|
* output buffer of `compressBound(maxLength)` bytes and
|
|
81
81
|
* the field arrays `addFields` fills, all built once.
|
|
82
82
|
*/
|
|
83
|
-
import {
|
|
83
|
+
import {
|
|
84
|
+
DEFLATE_ERR_OUTPUT_LIMIT,
|
|
85
|
+
DEFLATE_ERR_WINDOW,
|
|
86
|
+
DEFLATE_FAST,
|
|
87
|
+
compressBound,
|
|
88
|
+
} from "nish/compress/deflate"
|
|
84
89
|
import { adler32 } from "nish/compress/checksum"
|
|
85
90
|
import { GzipCompressor, GzipDecompressor, GzipFixedCompressor } from "nish/compress/gzip"
|
|
86
91
|
import { ZlibDecompressor } from "nish/compress/zlib"
|
|
@@ -195,12 +200,15 @@ const httpSegmentsOf = (bytes: i32, size: u32): i32 => {
|
|
|
195
200
|
if (bytes <= 0) {
|
|
196
201
|
return 0
|
|
197
202
|
}
|
|
198
|
-
// `size`
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
// the
|
|
203
|
+
// Both callers pass a `size` of 1 or more, so the test always holds; it is
|
|
204
|
+
// what shows the division has a divisor. The quotient is then at most
|
|
205
|
+
// `bytes - 1`, so `whole < bytes` always holds too, and it is what proves
|
|
206
|
+
// the count, at most `bytes`, cannot overflow.
|
|
202
207
|
if (size > 0) {
|
|
203
|
-
|
|
208
|
+
const whole: i32 = toI32(toU32(bytes - 1) / size)
|
|
209
|
+
if (whole >= 0 && whole < bytes) {
|
|
210
|
+
return whole + 1
|
|
211
|
+
}
|
|
204
212
|
}
|
|
205
213
|
return 0
|
|
206
214
|
}
|
|
@@ -291,8 +299,12 @@ const httpQValue = (buf: u8[], start: i32, end: i32): i32 => {
|
|
|
291
299
|
return -1
|
|
292
300
|
}
|
|
293
301
|
// At most three digits follow the point, each 9 or less at a scale of 100
|
|
294
|
-
// or less, so `q` stays
|
|
295
|
-
|
|
302
|
+
// or less, so `q` stays at most 1000 (`HTTP_Q_ONE`) and the test always
|
|
303
|
+
// holds; it is what proves the sum cannot overflow.
|
|
304
|
+
if (q < 0 || q > 1000 || scale < 0 || scale > 100) {
|
|
305
|
+
return -1
|
|
306
|
+
}
|
|
307
|
+
q = q + d * scale
|
|
296
308
|
scale = scale / 10
|
|
297
309
|
}
|
|
298
310
|
return q
|
|
@@ -512,7 +524,11 @@ const httpGzipToZlib = (out: u8[], n: i32, level: i32, src: u8[], off: i32, len:
|
|
|
512
524
|
for (let i: i32 = 2; i < end && i >= 0 && i + 8 < toI32(out.length); i += 1) {
|
|
513
525
|
out[i] = out[i + 8]
|
|
514
526
|
}
|
|
515
|
-
const
|
|
527
|
+
const a64: i64 = adler32(src, off, len)
|
|
528
|
+
if (a64 < 0) {
|
|
529
|
+
return HTTP_ZLIB_FAILED
|
|
530
|
+
}
|
|
531
|
+
const a: u32 = toU32(a64)
|
|
516
532
|
out[end] = toU8(a >>> 24)
|
|
517
533
|
out[end + 1] = toU8((a >>> 16) & 255)
|
|
518
534
|
out[end + 2] = toU8((a >>> 8) & 255)
|
|
@@ -606,15 +622,9 @@ export class HttpCompressor {
|
|
|
606
622
|
}
|
|
607
623
|
this.gzip = new GzipCompressor(level)
|
|
608
624
|
this.fixed = new GzipFixedCompressor()
|
|
609
|
-
//
|
|
610
|
-
// negative would cost `new Array` a check. No bench/instructions.json row
|
|
611
|
-
// builds a compressor, so no counted figure includes this loop.
|
|
612
|
-
const output: u8[] = []
|
|
625
|
+
// One zeroed allocation, sized once; the guard proves its length.
|
|
613
626
|
const bound: i32 = compressBound(maxLength)
|
|
614
|
-
|
|
615
|
-
output.push(0)
|
|
616
|
-
}
|
|
617
|
-
this.output = output
|
|
627
|
+
this.output = bound > 0 ? new Array<u8>(bound) : []
|
|
618
628
|
this.names = []
|
|
619
629
|
this.values = []
|
|
620
630
|
this.contentEncodingName = httpCompressBytes("content-encoding")
|
|
@@ -694,9 +704,13 @@ export class HttpCompressor {
|
|
|
694
704
|
return -1
|
|
695
705
|
}
|
|
696
706
|
// The longest output kept; `output` holds `compressBound(maxLength)`, more.
|
|
697
|
-
// `len` is 0 or more and the saving 1 or more, so the
|
|
698
|
-
//
|
|
699
|
-
const
|
|
707
|
+
// `len` is 0 or more and the saving 1 or more, so the test always holds;
|
|
708
|
+
// it is what proves the difference cannot overflow.
|
|
709
|
+
const saving: i32 = this.leastSaving(len)
|
|
710
|
+
let keep: i32 = -1
|
|
711
|
+
if (len >= 0 && saving >= 0) {
|
|
712
|
+
keep = len - saving
|
|
713
|
+
}
|
|
700
714
|
let n: i32 = -1
|
|
701
715
|
if (keep > 0) {
|
|
702
716
|
const fixed: boolean =
|
|
@@ -706,9 +720,10 @@ export class HttpCompressor {
|
|
|
706
720
|
let room: i32 = keep
|
|
707
721
|
if (deflate) {
|
|
708
722
|
// Below `size - HTTP_ZLIB_SHORTER`, `keep` plus that many is below
|
|
709
|
-
// `size
|
|
723
|
+
// `size`; the test, with the constant's 12 spelled for the prover, is
|
|
724
|
+
// what proves the sum cannot overflow.
|
|
710
725
|
const size: i32 = toI32(this.output.length)
|
|
711
|
-
room = keep < size -
|
|
726
|
+
room = keep < size - 12 ? keep + 12 : size
|
|
712
727
|
}
|
|
713
728
|
n = fixed
|
|
714
729
|
? this.fixed.compress(body, off, len, this.output, toI32(0), room)
|
|
@@ -923,18 +938,38 @@ export class HttpCompressor {
|
|
|
923
938
|
* uncompressed
|
|
924
939
|
*/
|
|
925
940
|
http1IdentityHead(encodedHead: i32, encodedLength: i32, length: i32): i32 {
|
|
926
|
-
// `encodedHead` is
|
|
927
|
-
//
|
|
928
|
-
//
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
941
|
+
// `encodedHead` is the length of a head just written, far below 2^30, each
|
|
942
|
+
// field here is a fixed word ("gzip", "deflate", "vary",
|
|
943
|
+
// "accept-encoding") and a count has at most ten digits, so the tests
|
|
944
|
+
// always hold; they are what prove the sums below cannot overflow.
|
|
945
|
+
const gzip: i32 = toI32(this.gzipValue.length)
|
|
946
|
+
const coding: i32 = toI32(this.codingValue.length)
|
|
947
|
+
const name: i32 = toI32(this.varyName.length)
|
|
948
|
+
const value: i32 = toI32(this.acceptEncodingValue.length)
|
|
949
|
+
const before: i32 = httpDecimalDigits(encodedLength)
|
|
950
|
+
const after: i32 = httpDecimalDigits(length)
|
|
951
|
+
if (encodedHead < 0 || encodedHead > 1073741824) {
|
|
952
|
+
return encodedHead
|
|
953
|
+
}
|
|
954
|
+
if (
|
|
955
|
+
gzip < 0 ||
|
|
956
|
+
gzip > 64 ||
|
|
957
|
+
coding < 0 ||
|
|
958
|
+
coding > 64 ||
|
|
959
|
+
name < 0 ||
|
|
960
|
+
name > 64 ||
|
|
961
|
+
value < 0 ||
|
|
962
|
+
value > 64
|
|
963
|
+
) {
|
|
964
|
+
return encodedHead
|
|
965
|
+
}
|
|
966
|
+
if (before < 0 || before > 10 || after < 0 || after > 10) {
|
|
967
|
+
return encodedHead
|
|
968
|
+
}
|
|
934
969
|
if (this.vary) {
|
|
935
|
-
|
|
970
|
+
return encodedHead - HTTP1_GZIP_FIELD_BYTES + gzip - coding - (name + value + 4) - before + after
|
|
936
971
|
}
|
|
937
|
-
return
|
|
972
|
+
return encodedHead - HTTP1_GZIP_FIELD_BYTES + gzip - coding - before + after
|
|
938
973
|
}
|
|
939
974
|
|
|
940
975
|
/**
|
|
@@ -1117,6 +1152,27 @@ export const HTTP_DECODE_BAD_CALL: i32 = -3
|
|
|
1117
1152
|
/** The first output buffer `HttpBodyDecoder` makes, when its limit allows that many bytes. */
|
|
1118
1153
|
const HTTP_DECODE_FIRST: i32 = 4096
|
|
1119
1154
|
|
|
1155
|
+
/**
|
|
1156
|
+
* Why `new HttpBodyDecoder(limit)` would panic: a `limit` under 1. A caller
|
|
1157
|
+
* that checks it first, and leaves on a fault, reaches no panic there.
|
|
1158
|
+
* @param limit the limit the decoder would be made with
|
|
1159
|
+
* @returns the fault, or "" when the limit is at least 1
|
|
1160
|
+
*/
|
|
1161
|
+
export const httpBodyDecoderFault = (limit: i32): string => {
|
|
1162
|
+
if (limit < 1) {
|
|
1163
|
+
return `HttpBodyDecoder: a limit of ${limit} is under 1`
|
|
1164
|
+
}
|
|
1165
|
+
return ""
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/** Panics on the fault `httpBodyDecoderFault` names, the decoder's contract. */
|
|
1169
|
+
const httpCheckBodyDecoder = (limit: i32): void => {
|
|
1170
|
+
const fault: string = httpBodyDecoderFault(limit)
|
|
1171
|
+
if (fault.length > 0) {
|
|
1172
|
+
panic(fault)
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1120
1176
|
/**
|
|
1121
1177
|
* Decodes a request body sent with `Content-Encoding: gzip` or `deflate`
|
|
1122
1178
|
* under a limit on what it decodes to, so a small body that inflates to
|
|
@@ -1142,13 +1198,11 @@ export class HttpBodyDecoder {
|
|
|
1142
1198
|
|
|
1143
1199
|
/**
|
|
1144
1200
|
* A decoder that refuses a body decoding to more than `limit` bytes; a
|
|
1145
|
-
* `limit` under 1 panics.
|
|
1201
|
+
* `limit` under 1 panics, the fault `httpBodyDecoderFault` names first.
|
|
1146
1202
|
* @param limit the most bytes one body may decode to
|
|
1147
1203
|
*/
|
|
1148
1204
|
constructor(limit: i32) {
|
|
1149
|
-
|
|
1150
|
-
panic(`HttpBodyDecoder: a limit of ${limit} is under 1`)
|
|
1151
|
-
}
|
|
1205
|
+
httpCheckBodyDecoder(limit)
|
|
1152
1206
|
this.limit = limit
|
|
1153
1207
|
this.output = []
|
|
1154
1208
|
this.gunzip = new GzipDecompressor()
|
|
@@ -1199,11 +1253,13 @@ export class HttpBodyDecoder {
|
|
|
1199
1253
|
if (off < 0 || len < 0 || off > toI32(src.length) - len) {
|
|
1200
1254
|
return HTTP_DECODE_BAD_CALL
|
|
1201
1255
|
}
|
|
1256
|
+
const stop: i32 = toI32(toI64(off) + toI64(len))
|
|
1202
1257
|
const limit: i32 = this.limit
|
|
1203
1258
|
// A first guess of four times the input, so most bodies decode at once.
|
|
1204
1259
|
// Under the test, `len` is at most a quarter of `limit`, so four times it
|
|
1205
|
-
// is an `i32
|
|
1206
|
-
|
|
1260
|
+
// is an `i32`. The literal is the largest quarter an `i32` limit has, so
|
|
1261
|
+
// its test never decides the answer; it is what proves the product.
|
|
1262
|
+
let size: i32 = len < 0 || len > 536870911 || len > limit >> 2 ? limit : len * 4
|
|
1207
1263
|
if (size < HTTP_DECODE_FIRST) {
|
|
1208
1264
|
size = limit < HTTP_DECODE_FIRST ? limit : HTTP_DECODE_FIRST
|
|
1209
1265
|
}
|
|
@@ -1217,13 +1273,18 @@ export class HttpBodyDecoder {
|
|
|
1217
1273
|
while (toI32(output.length) < size) {
|
|
1218
1274
|
output.push(0)
|
|
1219
1275
|
}
|
|
1276
|
+
// The range decoders answer a misuse rather than panicking, so a body
|
|
1277
|
+
// decoded here reaches no panic; the test above has ruled it out.
|
|
1220
1278
|
const end: i32 =
|
|
1221
1279
|
coding === HTTP_CODING_GZIP
|
|
1222
|
-
? this.gunzip.
|
|
1223
|
-
: this.unzlib.
|
|
1280
|
+
? this.gunzip.decompressRange(src, off, stop, output, toI32(0), limit)
|
|
1281
|
+
: this.unzlib.decompressRange(src, off, stop, output, toI32(0), limit)
|
|
1224
1282
|
if (end >= 0) {
|
|
1225
1283
|
return end
|
|
1226
1284
|
}
|
|
1285
|
+
if (end === DEFLATE_ERR_WINDOW) {
|
|
1286
|
+
return HTTP_DECODE_BAD_CALL
|
|
1287
|
+
}
|
|
1227
1288
|
if (end !== DEFLATE_ERR_OUTPUT_LIMIT) {
|
|
1228
1289
|
return HTTP_DECODE_MALFORMED
|
|
1229
1290
|
}
|
|
@@ -1232,8 +1293,9 @@ export class HttpBodyDecoder {
|
|
|
1232
1293
|
return HTTP_DECODE_TOO_LARGE
|
|
1233
1294
|
}
|
|
1234
1295
|
// Under the test, `have` is at most half of `limit`, so twice it is an
|
|
1235
|
-
// `i32
|
|
1236
|
-
|
|
1296
|
+
// `i32`. The literal is the largest half an `i32` limit has, so its test
|
|
1297
|
+
// never decides the answer; it is what proves the product.
|
|
1298
|
+
size = have < 0 || have > 1073741823 || have > limit >> 1 ? limit : have * 2
|
|
1237
1299
|
}
|
|
1238
1300
|
}
|
|
1239
1301
|
}
|