@amritk/nish-x86_64-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/http3.ts
CHANGED
|
@@ -212,7 +212,6 @@ import {
|
|
|
212
212
|
H3_WT_SESSION_GONE,
|
|
213
213
|
Http3FrameHeader,
|
|
214
214
|
Http3Settings,
|
|
215
|
-
h3CheckWindow,
|
|
216
215
|
h3Count,
|
|
217
216
|
h3FrameHeaderSize,
|
|
218
217
|
h3PutFrameHeader,
|
|
@@ -409,11 +408,61 @@ export class Http3Config {
|
|
|
409
408
|
resetBudget: i32 = 100
|
|
410
409
|
}
|
|
411
410
|
|
|
412
|
-
/**
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
411
|
+
/** Why `value` is not in `[low, high]`, or "" when it is. */
|
|
412
|
+
const http3CapFault = (what: string, value: i64, low: i64, high: i64): string =>
|
|
413
|
+
value < low || value > high ? `Http3Connection: ${what} of ${value}, outside ${low} to ${high}` : ""
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Why `config` over `quic` is not a connection this module can run, or ""
|
|
417
|
+
* when it is: the rules the `Http3Connection` constructor documents, the
|
|
418
|
+
* first broken one named.
|
|
419
|
+
*/
|
|
420
|
+
const http3ConnectionFault = (config: Http3Config, quic: QuicConnection): string => {
|
|
421
|
+
// The most a section may be: half a buffer less a frame header. Widened
|
|
422
|
+
// from two `i32`s, so the difference cannot wrap.
|
|
423
|
+
const room: i64 = toI64(quic.streams.bufferSize / 2) - toI64(H3_HEAD)
|
|
424
|
+
const bidi: i64 = quic.streams.maxBidi
|
|
425
|
+
// A HEADERS frame is read once all of it is in the stream's buffer, and QUIC
|
|
426
|
+
// gives more credit only once half a buffer has been read, so the frame
|
|
427
|
+
// may be at most half a buffer, its header aside, or it could stall.
|
|
428
|
+
const caps: string[] = [
|
|
429
|
+
http3CapFault("maxFieldSectionSize", toI64(config.maxFieldSectionSize), toI64(1), room),
|
|
430
|
+
http3CapFault("the QUIC bidirectional stream limit", bidi, toI64(0), toI64(1024)),
|
|
431
|
+
http3CapFault("bodyChunk", toI64(config.bodyChunk), toI64(1), toI64(H3_MAX_CHUNK)),
|
|
432
|
+
http3CapFault("writeChunk", toI64(config.writeChunk), toI64(1), toI64(H3_MAX_CHUNK)),
|
|
433
|
+
http3CapFault("the QUIC unidirectional stream limit", quic.streams.maxUni, toI64(3), toI64(1024)),
|
|
434
|
+
http3CapFault("the QUIC local stream limit", quic.streams.localStreams, toI64(3), toI64(1024)),
|
|
435
|
+
http3CapFault(
|
|
436
|
+
"webtransportSessions",
|
|
437
|
+
toI64(config.webtransportSessions),
|
|
438
|
+
toI64(0),
|
|
439
|
+
toI64(H3_MAX_SESSIONS)
|
|
440
|
+
),
|
|
441
|
+
http3CapFault("resetBudget", toI64(config.resetBudget), toI64(0), toI64(2147483647)),
|
|
442
|
+
http3CapFault("idleTimeout", toI64(config.idleTimeout), toI64(1), toI64(2147483647)),
|
|
443
|
+
http3CapFault("headTimeout", toI64(config.headTimeout), toI64(1), toI64(2147483647)),
|
|
444
|
+
]
|
|
445
|
+
for (const fault of caps) {
|
|
446
|
+
if (fault.length > 0) {
|
|
447
|
+
return fault
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// The connection's credit too: every request stream may hold a HEADERS
|
|
451
|
+
// frame not yet whole, and QUIC raises MAX_DATA once half the window is read.
|
|
452
|
+
// The window must hold `bidi` times `each`; dividing tests that with no product to overflow.
|
|
453
|
+
const each: i64 = toI64(2) * toI64(config.maxFieldSectionSize) + toI64(2) * toI64(H3_HEAD)
|
|
454
|
+
if (bidi > 0 && quic.streams.windowData / bidi < each) {
|
|
455
|
+
return `Http3Connection: a connection window of ${quic.streams.windowData}, under ${each} bytes for each of ${bidi} request streams' field sections`
|
|
456
|
+
}
|
|
457
|
+
// RFC 9297 §2.1.1: QUIC datagrams carry HTTP datagrams, which only WebTransport uses here.
|
|
458
|
+
const datagrams: boolean = quic.datagramsIn.capacity() > 0
|
|
459
|
+
if (config.webtransportSessions > 0 && !datagrams) {
|
|
460
|
+
return "Http3Connection: WebTransport needs QUIC datagrams, and the QUIC maxDatagramFrameSize is 0"
|
|
461
|
+
}
|
|
462
|
+
if (config.webtransportSessions === 0 && datagrams) {
|
|
463
|
+
return "Http3Connection: QUIC datagrams advertised with WebTransport off (webtransportSessions 0)"
|
|
464
|
+
}
|
|
465
|
+
return ""
|
|
417
466
|
}
|
|
418
467
|
|
|
419
468
|
/**
|
|
@@ -644,58 +693,41 @@ export class Http3Connection {
|
|
|
644
693
|
private connect: boolean = false
|
|
645
694
|
/** Whether WebTransport is on: `webtransportSessions` above 0. Fixed by the constructor. */
|
|
646
695
|
webtransport: boolean = false
|
|
696
|
+
/**
|
|
697
|
+
* Why the configuration does not fit the QUIC connection, the rule it
|
|
698
|
+
* breaks, or "" when it fits. Fixed by the constructor; while it is set the
|
|
699
|
+
* connection is failed with H3_INTERNAL_ERROR, and `restart` fails it again.
|
|
700
|
+
*/
|
|
701
|
+
fault: string = ""
|
|
647
702
|
|
|
648
703
|
/**
|
|
649
704
|
* A connection under `config` over `quic`, whose configuration must let a
|
|
650
705
|
* HEADERS frame of `maxFieldSectionSize` fit half a stream's buffer, and
|
|
651
706
|
* one on every request stream fit half the connection's window, and let
|
|
652
707
|
* the client open the three unidirectional streams it needs and this side
|
|
653
|
-
* open its own three (§6.2). Each QUIC stream limit is at most 1,024. A
|
|
654
|
-
* out of range
|
|
708
|
+
* open its own three (§6.2). Each QUIC stream limit is at most 1,024. A
|
|
709
|
+
* configuration that breaks one of these rules, a cap out of range, makes a
|
|
710
|
+
* connection that is failed from the start with H3_INTERNAL_ERROR, QUIC
|
|
711
|
+
* closing, and `fault` naming the rule.
|
|
655
712
|
*
|
|
656
713
|
* @param config The caps; kept, not copied, so it must not change after this call.
|
|
657
714
|
* @param quic The server QUIC connection to run on, kept for this connection's life. Its stream caps
|
|
658
715
|
* are checked as above, and it must take DATAGRAM frames exactly when `webtransportSessions` is above
|
|
659
|
-
* 0, or
|
|
716
|
+
* 0, or the connection fails as above.
|
|
660
717
|
*/
|
|
661
718
|
constructor(config: Http3Config, quic: QuicConnection) {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
//
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
const bidi: i64 = quic.streams.maxBidi
|
|
671
|
-
http3CheckCap("the QUIC bidirectional stream limit", toI32(bidi), 0, 1024)
|
|
672
|
-
const each: i64 = toI64(2) * toI64(config.maxFieldSectionSize) + toI64(2) * toI64(H3_HEAD)
|
|
673
|
-
if (bidi > 0 && quic.streams.windowData / bidi < each) {
|
|
674
|
-
panic(
|
|
675
|
-
`Http3Connection: a connection window of ${quic.streams.windowData}, under ${each} bytes for each of ${bidi} request streams' field sections`
|
|
676
|
-
)
|
|
677
|
-
}
|
|
678
|
-
http3CheckCap("bodyChunk", config.bodyChunk, 1, H3_MAX_CHUNK)
|
|
679
|
-
http3CheckCap("writeChunk", config.writeChunk, 1, H3_MAX_CHUNK)
|
|
680
|
-
http3CheckCap("the QUIC unidirectional stream limit", toI32(quic.streams.maxUni), 3, 1024)
|
|
681
|
-
http3CheckCap("the QUIC local stream limit", toI32(quic.streams.localStreams), 3, 1024)
|
|
682
|
-
http3CheckCap("webtransportSessions", config.webtransportSessions, 0, H3_MAX_SESSIONS)
|
|
683
|
-
http3CheckCap("resetBudget", config.resetBudget, 0, 2147483647)
|
|
684
|
-
http3CheckCap("idleTimeout", config.idleTimeout, 1, 2147483647)
|
|
685
|
-
http3CheckCap("headTimeout", config.headTimeout, 1, 2147483647)
|
|
686
|
-
// RFC 9297 §2.1.1: QUIC datagrams carry HTTP datagrams, which only WebTransport uses here.
|
|
687
|
-
const datagrams: boolean = quic.datagramsIn.capacity() > 0
|
|
688
|
-
if (config.webtransportSessions > 0 && !datagrams) {
|
|
689
|
-
panic("Http3Connection: WebTransport needs QUIC datagrams, and the QUIC maxDatagramFrameSize is 0")
|
|
690
|
-
}
|
|
691
|
-
if (config.webtransportSessions === 0 && datagrams) {
|
|
692
|
-
panic("Http3Connection: QUIC datagrams advertised with WebTransport off (webtransportSessions 0)")
|
|
693
|
-
}
|
|
694
|
-
this.webtransport = config.webtransportSessions > 0
|
|
719
|
+
const fault: string = http3ConnectionFault(config, quic)
|
|
720
|
+
const fits: boolean = fault.length === 0
|
|
721
|
+
this.fault = fault
|
|
722
|
+
// A configuration that does not fit fails the connection at once (below,
|
|
723
|
+
// and again on every `restart`), so it gets the smallest buffers instead.
|
|
724
|
+
const sectionSize: i32 = fits ? config.maxFieldSectionSize : H3_ONE
|
|
725
|
+
const bodyChunk: i32 = fits ? config.bodyChunk : H3_ONE
|
|
726
|
+
this.webtransport = fits && config.webtransportSessions > 0
|
|
695
727
|
this.connect = config.extendedConnect || this.webtransport
|
|
696
728
|
this.config = config
|
|
697
729
|
this.quic = quic
|
|
698
|
-
this.decoder = new QpackDecoder(
|
|
730
|
+
this.decoder = new QpackDecoder(sectionSize)
|
|
699
731
|
this.encoder = new QpackEncoder()
|
|
700
732
|
this.fields = new HttpFields()
|
|
701
733
|
this.peer = new Http3Settings()
|
|
@@ -703,8 +735,8 @@ export class Http3Connection {
|
|
|
703
735
|
this.none = []
|
|
704
736
|
this.data = this.none
|
|
705
737
|
this.section = this.none
|
|
706
|
-
this.dataPool = new BufferPool("Http3Connection.data",
|
|
707
|
-
this.sectionPool = new BufferPool("Http3Connection.section",
|
|
738
|
+
this.dataPool = new BufferPool("Http3Connection.data", bodyChunk, 1)
|
|
739
|
+
this.sectionPool = new BufferPool("Http3Connection.section", sectionSize, 1)
|
|
708
740
|
quicStreamGrowFree(this.dataPool.free, 1, this.none)
|
|
709
741
|
quicStreamGrowFree(this.sectionPool.free, 1, this.none)
|
|
710
742
|
this.control = new Array<u8>(H3_CONTROL_FRAME_MAX)
|
|
@@ -728,7 +760,7 @@ export class Http3Connection {
|
|
|
728
760
|
H3_SETTINGS_QPACK_BLOCKED_STREAMS,
|
|
729
761
|
H3_SETTINGS_MAX_FIELD_SECTION_SIZE,
|
|
730
762
|
]
|
|
731
|
-
this.settingValues = [toI64(0), toI64(0), toI64(
|
|
763
|
+
this.settingValues = [toI64(0), toI64(0), toI64(sectionSize)]
|
|
732
764
|
if (this.connect) {
|
|
733
765
|
this.settingIds.push(H3_SETTINGS_ENABLE_CONNECT_PROTOCOL)
|
|
734
766
|
this.settingValues.push(toI64(1))
|
|
@@ -743,8 +775,9 @@ export class Http3Connection {
|
|
|
743
775
|
}
|
|
744
776
|
// `QuicStreams` builds one slot per stream its three limits allow, each
|
|
745
777
|
// checked above to be at most 1,024, so the table holds at most 3,072
|
|
746
|
-
// and the `u16` holds it and every table below exactly
|
|
747
|
-
|
|
778
|
+
// and the `u16` holds it and every table below exactly; a connection
|
|
779
|
+
// that does not fit tracks no stream.
|
|
780
|
+
const n: u16 = fits ? toU16(quic.streams.slots.length) : toU16(0)
|
|
748
781
|
const bytes: u16 = toU16(toI32(n) * H3_HEAD)
|
|
749
782
|
this.slotId = new Array<i64>(n)
|
|
750
783
|
this.frameType = new Array<i64>(n)
|
|
@@ -825,6 +858,9 @@ export class Http3Connection {
|
|
|
825
858
|
this.resetCredit = this.config.resetBudget
|
|
826
859
|
this.settingsSeen = false
|
|
827
860
|
this.resetByPeer = false
|
|
861
|
+
if (this.fault.length > 0) {
|
|
862
|
+
this.fail(H3_INTERNAL_ERROR)
|
|
863
|
+
}
|
|
828
864
|
}
|
|
829
865
|
|
|
830
866
|
// ---- The connection -----------------------------------------------------------
|
|
@@ -1361,7 +1397,15 @@ export class Http3Connection {
|
|
|
1361
1397
|
}
|
|
1362
1398
|
have = have + n
|
|
1363
1399
|
headLens[k] = have
|
|
1364
|
-
|
|
1400
|
+
const end: i32 = base + have
|
|
1401
|
+
const head: u8[] = this.head
|
|
1402
|
+
// Never: slot `k`'s H3_HEAD bytes lie inside `head`, which nothing resizes.
|
|
1403
|
+
// Were it taken, the connection fails, as `controlFrame`'s does.
|
|
1404
|
+
if (base < 0 || base > end || end > toI32(head.length)) {
|
|
1405
|
+
this.fail(H3_INTERNAL_ERROR)
|
|
1406
|
+
return H3_ZERO
|
|
1407
|
+
}
|
|
1408
|
+
if (h3ReadFrameHeader(this.header, head, base, end - base) > 0) {
|
|
1365
1409
|
if (k < toI32(headLens.length)) {
|
|
1366
1410
|
headLens[k] = 0
|
|
1367
1411
|
}
|
|
@@ -1422,10 +1466,15 @@ export class Http3Connection {
|
|
|
1422
1466
|
if (n < 0) {
|
|
1423
1467
|
return this.fail(H3_CLOSED_CRITICAL_STREAM)
|
|
1424
1468
|
}
|
|
1469
|
+
const data: u8[] = this.data
|
|
1470
|
+
if (n > toI32(data.length)) {
|
|
1471
|
+
return this.fail(H3_INTERNAL_ERROR) // never: `readData` reads at most the buffer it fills
|
|
1472
|
+
}
|
|
1473
|
+
const start: i32 = 0
|
|
1425
1474
|
const result: i64 =
|
|
1426
1475
|
phase === H3_PHASE_ENCODER
|
|
1427
|
-
? this.decoder.receiveEncoderStream(
|
|
1428
|
-
: this.encoder.receiveDecoderStream(
|
|
1476
|
+
? this.decoder.receiveEncoderStream(data, start, n)
|
|
1477
|
+
: this.encoder.receiveDecoderStream(data, start, n)
|
|
1429
1478
|
if (result !== QPACK_OK) {
|
|
1430
1479
|
return this.fail(result)
|
|
1431
1480
|
}
|
|
@@ -1566,8 +1615,14 @@ export class Http3Connection {
|
|
|
1566
1615
|
|
|
1567
1616
|
/** Acts on a whole control frame of `type` in `control[0 .. controlFill)`. */
|
|
1568
1617
|
private controlFrame(type: i64): i32 {
|
|
1618
|
+
const control: u8[] = this.control
|
|
1619
|
+
const fill: i32 = this.controlFill
|
|
1620
|
+
// Never: `controlStep` keeps `controlFill` within `control`, which nothing resizes.
|
|
1621
|
+
if (fill < 0 || fill > toI32(control.length)) {
|
|
1622
|
+
return this.fail(H3_INTERNAL_ERROR)
|
|
1623
|
+
}
|
|
1569
1624
|
if (type === H3_FRAME_SETTINGS) {
|
|
1570
|
-
const result: i64 = h3ReadSettings(this.peer,
|
|
1625
|
+
const result: i64 = h3ReadSettings(this.peer, control, 0, fill)
|
|
1571
1626
|
if (result !== H3_SETTINGS_OK) {
|
|
1572
1627
|
return this.fail(result)
|
|
1573
1628
|
}
|
|
@@ -1596,7 +1651,7 @@ export class Http3Connection {
|
|
|
1596
1651
|
if (type === H3_SKIP_TYPE) {
|
|
1597
1652
|
return H3_NEED_MORE
|
|
1598
1653
|
}
|
|
1599
|
-
const value: i64 = h3ReadIdPayload(
|
|
1654
|
+
const value: i64 = h3ReadIdPayload(control, 0, fill)
|
|
1600
1655
|
if (value < 0) {
|
|
1601
1656
|
return this.fail(H3_FRAME_ERROR)
|
|
1602
1657
|
}
|
|
@@ -1883,7 +1938,7 @@ export class Http3Connection {
|
|
|
1883
1938
|
* many it took — fewer only when the send buffer filled, and H3_WRITABLE
|
|
1884
1939
|
* then names the stream — or H3_AGAIN when it took none, or H3_CLOSED for
|
|
1885
1940
|
* a stream with no side here to write, finished, reset, held or stopped.
|
|
1886
|
-
* A window outside `buf`
|
|
1941
|
+
* A window outside `buf` answers H3_INVALID, before anything about the stream is asked.
|
|
1887
1942
|
*
|
|
1888
1943
|
* @param id A WebTransport stream this side writes, accepted or opened by `openStream`.
|
|
1889
1944
|
* @param buf The bytes; copied into the stream's send buffer, so the caller may reuse it.
|
|
@@ -1891,10 +1946,14 @@ export class Http3Connection {
|
|
|
1891
1946
|
* @param len How many bytes to offer; 0 with `fin` sends only the FIN.
|
|
1892
1947
|
* @param fin True to finish this side of the stream once all `len` bytes are taken.
|
|
1893
1948
|
* @returns The bytes taken, 1 to `len`, or 0 for a FIN alone; H3_AGAIN when it took none, a `len` of
|
|
1894
|
-
* 0 without `fin` among them; H3_CLOSED as above, or any stream once the connection has failed
|
|
1949
|
+
* 0 without `fin` among them; H3_CLOSED as above, or any stream once the connection has failed;
|
|
1950
|
+
* H3_INVALID for a window outside `buf`.
|
|
1895
1951
|
*/
|
|
1896
1952
|
writeStream(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
|
|
1897
|
-
|
|
1953
|
+
const size: i32 = toI32(buf.length)
|
|
1954
|
+
if (off < 0 || len < 0 || off > size || len > size - off) {
|
|
1955
|
+
return H3_INVALID
|
|
1956
|
+
}
|
|
1898
1957
|
const k: i32 = this.wtSlot(id)
|
|
1899
1958
|
const slots: QuicStream[] = this.quic.streams.slots
|
|
1900
1959
|
if (
|
|
@@ -2224,7 +2283,12 @@ export class Http3Connection {
|
|
|
2224
2283
|
* checks it there.
|
|
2225
2284
|
*/
|
|
2226
2285
|
private fieldSection(k: i32, id: i64, length: i32): i32 {
|
|
2227
|
-
const
|
|
2286
|
+
const section: u8[] = this.section
|
|
2287
|
+
if (length < 0 || length > toI32(section.length)) {
|
|
2288
|
+
return this.fail(H3_INTERNAL_ERROR) // never: `requestStep` passes a payload it holds whole in `section`
|
|
2289
|
+
}
|
|
2290
|
+
const start: i32 = 0
|
|
2291
|
+
const result: i64 = this.decoder.decode(section, start, length)
|
|
2228
2292
|
if (k < 0 || k >= toI32(this.phase.length)) {
|
|
2229
2293
|
return this.fail(H3_INTERNAL_ERROR) // never: `requestStep` holds a slot of the table, which nothing resizes
|
|
2230
2294
|
}
|
|
@@ -2709,23 +2773,13 @@ export class Http3Connection {
|
|
|
2709
2773
|
digits[2] = toU8(H3_DIGIT_ZERO + (status % 10))
|
|
2710
2774
|
const nameLength: i32 = toI32(this.statusName.length)
|
|
2711
2775
|
const valueLength: i32 = toI32(digits.length)
|
|
2712
|
-
this.encoder.
|
|
2713
|
-
out,
|
|
2714
|
-
this.statusName,
|
|
2715
|
-
H3_ZERO,
|
|
2716
|
-
nameLength,
|
|
2717
|
-
this.statusValue,
|
|
2718
|
-
H3_ZERO,
|
|
2719
|
-
valueLength,
|
|
2720
|
-
false,
|
|
2721
|
-
true
|
|
2722
|
-
)
|
|
2776
|
+
this.encoder.encodeWholeField(out, this.statusName, digits, false, true)
|
|
2723
2777
|
size = toI64(nameLength) + toI64(valueLength) + toI64(QPACK_FIELD_OVERHEAD)
|
|
2724
2778
|
}
|
|
2725
2779
|
if (dated && status >= 200 && toI32(this.date.length) > 0 && !http3NamesHoldDate(names)) {
|
|
2726
2780
|
const nl: i32 = toI32(this.dateName.length)
|
|
2727
2781
|
const vl: i32 = toI32(this.date.length)
|
|
2728
|
-
this.encoder.
|
|
2782
|
+
this.encoder.encodeWholeField(out, this.dateName, this.date, false, true)
|
|
2729
2783
|
if (size >= 0 && size < 1073741824) {
|
|
2730
2784
|
size = size + toI64(nl) + toI64(vl) + toI64(QPACK_FIELD_OVERHEAD)
|
|
2731
2785
|
}
|
|
@@ -2736,7 +2790,7 @@ export class Http3Connection {
|
|
|
2736
2790
|
const value: u8[] = values[j]
|
|
2737
2791
|
const nl: i32 = toI32(name.length)
|
|
2738
2792
|
const vl: i32 = toI32(value.length)
|
|
2739
|
-
this.encoder.
|
|
2793
|
+
this.encoder.encodeWholeField(out, name, value, httpFieldSensitive(name), true)
|
|
2740
2794
|
// The sum stops growing past 2^30 bytes: a section that size is past any stream buffer.
|
|
2741
2795
|
if (size >= 0 && size < 1073741824) {
|
|
2742
2796
|
size = size + toI64(nl) + toI64(vl) + toI64(QPACK_FIELD_OVERHEAD)
|
|
@@ -2859,7 +2913,7 @@ export class Http3Connection {
|
|
|
2859
2913
|
* took none;
|
|
2860
2914
|
* H3_CLOSED, or H3_INVALID before the head or when `endStream` would cut
|
|
2861
2915
|
* short the DATA frame the last call started.
|
|
2862
|
-
* A window outside `buf`
|
|
2916
|
+
* A window outside `buf` answers H3_INVALID, before anything about the stream is asked.
|
|
2863
2917
|
*
|
|
2864
2918
|
* @param id The request stream, after `respond`.
|
|
2865
2919
|
* @param buf The body bytes; copied into the stream's send buffer, so the caller may reuse it.
|
|
@@ -2871,10 +2925,13 @@ export class Http3Connection {
|
|
|
2871
2925
|
* left owed cannot go; H3_CLOSED for a stream that is not an open request: unknown, not yet handed
|
|
2872
2926
|
* to the program, its response finished or reset, stopped by the client, or any stream once the
|
|
2873
2927
|
* connection has failed;
|
|
2874
|
-
* H3_INVALID as above
|
|
2928
|
+
* H3_INVALID as above, or for a window outside `buf`.
|
|
2875
2929
|
*/
|
|
2876
2930
|
writeData(id: i64, buf: u8[], off: i32, len: i32, endStream: boolean): i32 {
|
|
2877
|
-
|
|
2931
|
+
const size: i32 = toI32(buf.length)
|
|
2932
|
+
if (off < 0 || len < 0 || off > size || len > size - off) {
|
|
2933
|
+
return H3_INVALID
|
|
2934
|
+
}
|
|
2878
2935
|
const k: i32 = this.writeSlot(id)
|
|
2879
2936
|
if (k < 0) {
|
|
2880
2937
|
return H3_CLOSED
|
|
@@ -2898,7 +2955,7 @@ export class Http3Connection {
|
|
|
2898
2955
|
return 0
|
|
2899
2956
|
}
|
|
2900
2957
|
if (len < 0) {
|
|
2901
|
-
return H3_INVALID // never:
|
|
2958
|
+
return H3_INVALID // never: the window test refused a negative length
|
|
2902
2959
|
}
|
|
2903
2960
|
// DATA frame after DATA frame, until every byte is taken or the send buffer is full.
|
|
2904
2961
|
let total: i32 = 0
|
|
@@ -2938,7 +2995,7 @@ export class Http3Connection {
|
|
|
2938
2995
|
const fin: boolean = endStream && take === want && toI64(take) === left
|
|
2939
2996
|
const at: i64 = toI64(off) + toI64(total)
|
|
2940
2997
|
if (at > 2147483647) {
|
|
2941
|
-
break // never:
|
|
2998
|
+
break // never: the window test put the window inside `buf`
|
|
2942
2999
|
}
|
|
2943
3000
|
const n: i32 = this.quic.streamWrite(id, buf, toI32(at), take, fin)
|
|
2944
3001
|
if (n < 0) {
|
|
@@ -2971,7 +3028,7 @@ export class Http3Connection {
|
|
|
2971
3028
|
* H3_AGAIN while the send buffer lacks room, and H3_WRITABLE then names the
|
|
2972
3029
|
* stream; or as `writeData` refuses, and H3_TOO_LARGE for a frame past the
|
|
2973
3030
|
* stream's buffer.
|
|
2974
|
-
* A window outside `buf`
|
|
3031
|
+
* A window outside `buf` answers H3_INVALID, before anything about the stream is asked.
|
|
2975
3032
|
*
|
|
2976
3033
|
* @param id The request stream, after `respond`.
|
|
2977
3034
|
* @param buf The frame's payload; copied into the stream's send buffer, so the caller may reuse it.
|
|
@@ -2982,10 +3039,14 @@ export class Http3Connection {
|
|
|
2982
3039
|
* it, and H3_WRITABLE then names the stream; H3_CLOSED for a stream that is not an open request:
|
|
2983
3040
|
* unknown, not yet handed to the program, its response finished or reset, stopped by the client, or
|
|
2984
3041
|
* any stream once the connection has failed;
|
|
2985
|
-
* H3_INVALID before the head
|
|
3042
|
+
* H3_INVALID before the head, inside a DATA frame `writeData` has not finished, or for a window
|
|
3043
|
+
* outside `buf`; H3_TOO_LARGE.
|
|
2986
3044
|
*/
|
|
2987
3045
|
writeDataWhole(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
|
|
2988
|
-
|
|
3046
|
+
const size: i32 = toI32(buf.length)
|
|
3047
|
+
if (off < 0 || len < 0 || off > size || len > size - off) {
|
|
3048
|
+
return H3_INVALID
|
|
3049
|
+
}
|
|
2989
3050
|
const k: i32 = this.writeSlot(id)
|
|
2990
3051
|
if (k < 0) {
|
|
2991
3052
|
return H3_CLOSED
|
|
@@ -2997,7 +3058,7 @@ export class Http3Connection {
|
|
|
2997
3058
|
return H3_INVALID
|
|
2998
3059
|
}
|
|
2999
3060
|
if (len < 0) {
|
|
3000
|
-
return H3_INVALID // never:
|
|
3061
|
+
return H3_INVALID // never: the window test refused a negative length
|
|
3001
3062
|
}
|
|
3002
3063
|
const head: i32 = h3FrameHeaderSize(H3_FRAME_DATA, toI64(len))
|
|
3003
3064
|
if (head < 0 || head > 16) {
|