Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(core): refuse incomplete undo table headers [H21,H16]

Corey Olson6808fcdf03e3
diff --git a/src/relay-outbox-undo.js b/src/relay-outbox-undo.js
index f193dfee..f082613b 100644
--- a/src/relay-outbox-undo.js
+++ b/src/relay-outbox-undo.js
@@ -74,6 +74,9 @@ export function invertChangeset(changeset) {
const count = varint(bytes, at + 1);
columns = count.value;
const end = bytes.indexOf(0, count.next + columns);
+ if (!Number.isSafeInteger(columns) || columns < 1 || count.next + columns >= bytes.length || end < 0) {
+ throw new Error('a changeset table header is incomplete');
+ }
out.push(bytes.subarray(at, end + 1));
at = end + 1;
continue;
diff --git a/test/relay-outbox-undo.test.js b/test/relay-outbox-undo.test.js
index 0dad74f8..54a15b55 100644
--- a/test/relay-outbox-undo.test.js
+++ b/test/relay-outbox-undo.test.js
@@ -92,3 +92,12 @@ test('outbox undo refuses a foreign key conflict and restores its transaction [H
assert.deepEqual(image(board), before);
assert.deepEqual(board.db.prepare('PRAGMA foreign_key_check').all(), []);
});
+
+
+test('outbox undo rejects an unterminated table header and rolls back its setup [H21,H16]', t => {
+ const board = fixture(t, "CREATE TABLE sample (id INTEGER PRIMARY KEY, value TEXT); INSERT INTO sample VALUES(1,'kept')");
+ const before = image(board);
+ const malformed = Buffer.from([0x54, 1, 1, 0x61]).toString('base64');
+ assert.throws(() => undoQueued(board, [{ changes: [malformed] }]), /table header is incomplete/);
+ assert.deepEqual(image(board), before);
+});