From f3ca435c768756dcd8c4d2324a38dc74933f57ed Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Thu, 19 Sep 2024 15:23:45 +0200 Subject: [PATCH] PG-1038 Add regression tests that causes PG crash --- expected/tablespace.out | 1 + sql/tablespace.sql | 26 ++++++++++++++++++++++++++ src/access/pg_tde_slot.c | 3 +++ 3 files changed, 30 insertions(+) create mode 100644 expected/tablespace.out create mode 100644 sql/tablespace.sql diff --git a/expected/tablespace.out b/expected/tablespace.out new file mode 100644 index 00000000..0ffdd02f --- /dev/null +++ b/expected/tablespace.out @@ -0,0 +1 @@ +// TODO \ No newline at end of file diff --git a/sql/tablespace.sql b/sql/tablespace.sql new file mode 100644 index 00000000..ecd7aa32 --- /dev/null +++ b/sql/tablespace.sql @@ -0,0 +1,26 @@ +CREATE EXTENSION pg_tde; + +SELECT * FROM pg_tde_principal_key_info(); + +SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); +SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); + + +CREATE TABLE test(num1 bigint, num2 double precision, t text); +INSERT INTO test(num1, num2, t) + SELECT round(random()*100), random(), 'text' + FROM generate_series(1, 10) s(i); +CREATE INDEX test_idx ON test(num1); + +SET allow_in_place_tablespaces = true; +CREATE TABLESPACE test_tblspace LOCATION ''; + +ALTER TABLE test SET TABLESPACE test_tblspace; +ALTER TABLE test SET TABLESPACE pg_default; + +REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test; +INSERT INTO test VALUES (10, 2); + +DROP TABLE test; +DROP TABLESPACE test_tblspace; +DROP EXTENSION pg_tde; diff --git a/src/access/pg_tde_slot.c b/src/access/pg_tde_slot.c index cc989d20..b4253bc4 100644 --- a/src/access/pg_tde_slot.c +++ b/src/access/pg_tde_slot.c @@ -511,6 +511,9 @@ PGTdeExecStoreBufferHeapTuple(Relation rel, if (rel->rd_rel->relkind != RELKIND_TOASTVALUE) { RelKeyData *key = get_current_slot_relation_key(bslot, rel); + + Assert(key != NULL); + slot_copytuple(bslot->decrypted_buffer, tuple); PG_TDE_DECRYPT_TUPLE_EX(tuple, (HeapTuple)bslot->decrypted_buffer, key, "ExecStoreBuffer"); tuple->t_data = ((HeapTuple)bslot->decrypted_buffer)->t_data;