Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
/live closes any text frame over 4096 bytes with 1009 - the three-line cap plus its boundary tests #199
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/188-live-closes-any-text-frame-over-4096-byt → main 1 commit fork
2 files
changed +43
−0
Software/so101/src/lobby.test.ts +41
| @@ -661,4 +661,45 @@ describe("lobby", () => { | ||
| 661 | 661 | arm.close(); |
| 662 | 662 | } |
| 663 | 663 | }); |
| 664 | ||
| 665 | describe("/live frame size", () => { | |
| 666 | /** A JSON object of exactly `bytes` bytes, its padding made of `ch` (of `width` bytes each). */ | |
| 667 | const padded = (bytes: number, ch = "a", width = 1) => { | |
| 668 | const head = '{"type":"nope","pad":"'; | |
| 669 | const fill = bytes - head.length - 2; | |
| 670 | return head + ch.repeat(Math.floor(fill / width)) + "a".repeat(fill % width) + '"}'; | |
| 671 | }; | |
| 672 | const closing = (ws: WebSocket) => new Promise<number>((resolve) => ws.once("close", (code) => resolve(code))); | |
| 673 | ||
| 674 | test("4096 bytes are handled and the socket stays open", async () => { | |
| 675 | const port = await start(); | |
| 676 | const c = await join(port); | |
| 677 | const text = padded(4096); | |
| 678 | expect(Buffer.byteLength(text)).toBe(4096); | |
| 679 | c.ws.send(text); | |
| 680 | await c.next((m) => m.type === "error"); | |
| 681 | expect(c.ws.readyState).toBe(WebSocket.OPEN); | |
| 682 | }); | |
| 683 | ||
| 684 | test("4097 bytes close with 1009", async () => { | |
| 685 | const port = await start(); | |
| 686 | const c = await join(port); | |
| 687 | const text = padded(4097); | |
| 688 | expect(Buffer.byteLength(text)).toBe(4097); | |
| 689 | const code = closing(c.ws); | |
| 690 | c.ws.send(text); | |
| 691 | expect(await code).toBe(1009); | |
| 692 | }); | |
| 693 | ||
| 694 | test("1366 three-byte characters (4098 bytes) close with 1009", async () => { | |
| 695 | const port = await start(); | |
| 696 | const c = await join(port); | |
| 697 | const text = "€".repeat(1366); | |
| 698 | expect(text.length).toBeLessThan(4096); | |
| 699 | expect(Buffer.byteLength(text)).toBe(4098); | |
| 700 | const code = closing(c.ws); | |
| 701 | c.ws.send(text); | |
| 702 | expect(await code).toBe(1009); | |
| 703 | }); | |
| 704 | }); | |
| 664 | 705 | }); |
Software/so101/src/lobby.ts +2
| @@ -34,6 +34,7 @@ import type { Duplex } from "node:stream"; | ||
| 34 | 34 | import WebSocket, { WebSocketServer } from "ws"; |
| 35 | 35 | import { Accounts, visitor, type Visitor } from "./accounts.ts"; |
| 36 | 36 | import { Admin, AdminError } from "./admin.ts"; |
| 37 | import { frameBytes, TOO_BIG_CLOSE } from "./frame-limit.ts"; | |
| 37 | 38 | import { Chat, ChatError } from "./chat.ts"; |
| 38 | 39 | import { Moderator } from "./moderator.ts"; |
| 39 | 40 | import { WordFilter } from "./word-filter.ts"; |
| @@ -261,6 +262,7 @@ export class Lobby { | ||
| 261 | 262 | ws.on("message", (data, binary) => { |
| 262 | 263 | seat.heard = Date.now(); |
| 263 | 264 | if (binary) return; |
| 265 | if (frameBytes(data) > MAX_FRAME) return ws.close(TOO_BIG_CLOSE, "message too big"); | |
| 264 | 266 | let message: unknown; |
| 265 | 267 | try { |
| 266 | 268 | message = JSON.parse(String(data)); |
new above
offline