Files
aevolution/migrations/0032_fix_cellular_v3_manifest_normalization.sql
dingo a11f0c8e0f
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (postgres) (push) Failing after 32m36s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Fix cellular manifest parser alias collision
2026-10-12 03:00:34 -04:00

34 lines
1.6 KiB
PL/PgSQL

-- M11.4c, ADR-0122: normalize the v3 history field without changing manifest length.
-- The v27 parser used an eight-byte helper for this four-byte field, so overlay
-- enlarged the manifest and the v24 parser correctly rejected it as malformed.
-- Preserve v27's parser and intercept v3 manifests before its broken branch.
ALTER FUNCTION evolution.parse_checkpoint_manifest(bytea)
RENAME TO parse_checkpoint_manifest_v31;
CREATE FUNCTION evolution.parse_checkpoint_manifest(m bytea)
RETURNS evolution.checkpoint_manifest LANGUAGE plpgsql IMMUTABLE
SET search_path = pg_catalog, pg_temp AS $$
DECLARE
r evolution.checkpoint_manifest;
normalized bytea;
v2_bundle constant bytea := '\x020000000200000001000000010000000100000002000000010000000100000001000000';
v3_bundle constant bytea := '\x020000000300000001000000010000000100000002000000010000000200000001000000';
BEGIN
IF m IS NOT NULL AND octet_length(m) = 360
AND evolution.manifest_uint(m, 12, 4) = 4
AND substring(m FROM 161 FOR 36) = v3_bundle
AND evolution.manifest_uint(m, 228, 4) = 0
AND evolution.manifest_uint(m, 232, 4) = 4
AND evolution.manifest_uint(m, 236, 4) = 1 THEN
normalized := overlay(m PLACING v2_bundle FROM 161 FOR 36);
normalized := overlay(normalized PLACING decode('03000000', 'hex') FROM 233 FOR 4);
r := evolution.parse_checkpoint_manifest_v31(normalized);
r.versions := v3_bundle;
RETURN r;
END IF;
RETURN evolution.parse_checkpoint_manifest_v31(m);
END $$;
REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest(bytea) FROM PUBLIC;
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (32, :'migration_sha_32');