Skip to content

Commit

Permalink
Fix crash while deleting tuple w/ va attributes (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dAdAbird authored Feb 29, 2024
1 parent 210c95c commit 57cf804
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ non_sorted_off_compact \
update_compare_indexes \
pgtde_is_encrypted \
multi_insert \
trigger_on_view
trigger_on_view \
insert_update_delete
TAP_TESTS = 1

OBJS = src/encryption/enc_tde.o \
Expand Down
82 changes: 82 additions & 0 deletions expected/insert_update_delete.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
CREATE EXTENSION pg_tde;
CREATE TABLE albums (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;
INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
('Graindelavoix', 'Tenebrae Responsoria - Carlo Gesualdo', '2019-08-06'),
('Graindelavoix', 'Cypriot Vespers', '2015-12-20'),
('John Coltrane', 'Blue Train', '1957-09-15'),
('V/A Analog Africa', 'Space Echo - The Mystery Behind the Cosmic Sound of Cabo Verde Finally Revealed', '2016-05-27'),
('Incapacitants', 'As Loud As Possible', '2022-09-15'),
('Chris Corsano & Bill Orcutt', 'Made Out Of Sound', '2021-03-26'),
('Jürg Frey (Quatuor Bozzini / Konus Quartett)', 'Continuit​é​, fragilit​é​, r​é​sonance', '2023-04-01'),
('clipping.', 'Visions of Bodies Being Burned', '2020-10-23'),
('clipping.', 'There Existed an Addiction to Blood', '2019-10-19'),
('Autechre', 'elseq 1–5', '2016-05-19'),
('Decapitated', 'Winds of Creation', '2000-04-17'),
('Ulthar', 'Anthronomicon', '2023-02-17'),
('Τζίμης Πανούσης', 'Κάγκελα Παντού', '1986-01-01'),
('Воплі Відоплясова', 'Музіка', '1997-01-01');
SELECT * FROM albums;
id | artist | title | released
----+----------------------------------------------+---------------------------------------------------------------------------------+------------
1 | Graindelavoix | Jisquin The Undead | 06-12-2021
2 | Graindelavoix | Tenebrae Responsoria - Carlo Gesualdo | 08-06-2019
3 | Graindelavoix | Cypriot Vespers | 12-20-2015
4 | John Coltrane | Blue Train | 09-15-1957
5 | V/A Analog Africa | Space Echo - The Mystery Behind the Cosmic Sound of Cabo Verde Finally Revealed | 05-27-2016
6 | Incapacitants | As Loud As Possible | 09-15-2022
7 | Chris Corsano & Bill Orcutt | Made Out Of Sound | 03-26-2021
8 | Jürg Frey (Quatuor Bozzini / Konus Quartett) | Continuit​é​, fragilit​é​, r​é​sonance | 04-01-2023
9 | clipping. | Visions of Bodies Being Burned | 10-23-2020
10 | clipping. | There Existed an Addiction to Blood | 10-19-2019
11 | Autechre | elseq 1–5 | 05-19-2016
12 | Decapitated | Winds of Creation | 04-17-2000
13 | Ulthar | Anthronomicon | 02-17-2023
14 | Τζίμης Πανούσης | Κάγκελα Παντού | 01-01-1986
15 | Воплі Відоплясова | Музіка | 01-01-1997
(15 rows)

DELETE FROM albums WHERE id % 4 = 0;
SELECT * FROM albums;
id | artist | title | released
----+-----------------------------+---------------------------------------------------------------------------------+------------
1 | Graindelavoix | Jisquin The Undead | 06-12-2021
2 | Graindelavoix | Tenebrae Responsoria - Carlo Gesualdo | 08-06-2019
3 | Graindelavoix | Cypriot Vespers | 12-20-2015
5 | V/A Analog Africa | Space Echo - The Mystery Behind the Cosmic Sound of Cabo Verde Finally Revealed | 05-27-2016
6 | Incapacitants | As Loud As Possible | 09-15-2022
7 | Chris Corsano & Bill Orcutt | Made Out Of Sound | 03-26-2021
9 | clipping. | Visions of Bodies Being Burned | 10-23-2020
10 | clipping. | There Existed an Addiction to Blood | 10-19-2019
11 | Autechre | elseq 1–5 | 05-19-2016
13 | Ulthar | Anthronomicon | 02-17-2023
14 | Τζίμης Πανούσης | Κάγκελα Παντού | 01-01-1986
15 | Воплі Відоплясова | Музіка | 01-01-1997
(12 rows)

UPDATE albums SET title='Jisquin The Undead: Laments, Deplorations and Dances of Death', released='2021-10-01' WHERE id=1;
UPDATE albums SET released='2020-04-01' WHERE id=2;
SELECT * FROM albums;
id | artist | title | released
----+-----------------------------+---------------------------------------------------------------------------------+------------
3 | Graindelavoix | Cypriot Vespers | 12-20-2015
5 | V/A Analog Africa | Space Echo - The Mystery Behind the Cosmic Sound of Cabo Verde Finally Revealed | 05-27-2016
6 | Incapacitants | As Loud As Possible | 09-15-2022
7 | Chris Corsano & Bill Orcutt | Made Out Of Sound | 03-26-2021
9 | clipping. | Visions of Bodies Being Burned | 10-23-2020
10 | clipping. | There Existed an Addiction to Blood | 10-19-2019
11 | Autechre | elseq 1–5 | 05-19-2016
13 | Ulthar | Anthronomicon | 02-17-2023
14 | Τζίμης Πανούσης | Κάγκελα Παντού | 01-01-1986
15 | Воплі Відоплясова | Музіка | 01-01-1997
1 | Graindelavoix | Jisquin The Undead: Laments, Deplorations and Dances of Death | 10-01-2021
2 | Graindelavoix | Tenebrae Responsoria - Carlo Gesualdo | 04-01-2020
(12 rows)

DROP TABLE albums;
DROP EXTENSION pg_tde;
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tests += {
'pgtde_is_encrypted',
'multi_insert',
'trigger_on_view',
'insert_update_delete',
],
'regress_args': ['--temp-config', files('pg_tde.conf')],
'runningcheck': false,
Expand Down
38 changes: 38 additions & 0 deletions sql/insert_update_delete.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CREATE EXTENSION pg_tde;

CREATE TABLE albums (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde;

INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
('Graindelavoix', 'Tenebrae Responsoria - Carlo Gesualdo', '2019-08-06'),
('Graindelavoix', 'Cypriot Vespers', '2015-12-20'),
('John Coltrane', 'Blue Train', '1957-09-15'),
('V/A Analog Africa', 'Space Echo - The Mystery Behind the Cosmic Sound of Cabo Verde Finally Revealed', '2016-05-27'),
('Incapacitants', 'As Loud As Possible', '2022-09-15'),
('Chris Corsano & Bill Orcutt', 'Made Out Of Sound', '2021-03-26'),
('Jürg Frey (Quatuor Bozzini / Konus Quartett)', 'Continuit​é​, fragilit​é​, r​é​sonance', '2023-04-01'),
('clipping.', 'Visions of Bodies Being Burned', '2020-10-23'),
('clipping.', 'There Existed an Addiction to Blood', '2019-10-19'),
('Autechre', 'elseq 1–5', '2016-05-19'),
('Decapitated', 'Winds of Creation', '2000-04-17'),
('Ulthar', 'Anthronomicon', '2023-02-17'),
('Τζίμης Πανούσης', 'Κάγκελα Παντού', '1986-01-01'),
('Воплі Відоплясова', 'Музіка', '1997-01-01');

SELECT * FROM albums;

DELETE FROM albums WHERE id % 4 = 0;
SELECT * FROM albums;

UPDATE albums SET title='Jisquin The Undead: Laments, Deplorations and Dances of Death', released='2021-10-01' WHERE id=1;
UPDATE albums SET released='2020-04-01' WHERE id=2;

SELECT * FROM albums;

DROP TABLE albums;
DROP EXTENSION pg_tde;
12 changes: 10 additions & 2 deletions src/access/pg_tdeam.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ static XLogRecPtr log_pg_tde_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation relation, HeapTuple tp, bool key_required,
bool *copy);


/*
* Each tuple lock mode has a corresponding heavyweight lock, and one or two
* corresponding MultiXactStatuses (one to merely lock tuples, another one to
Expand Down Expand Up @@ -2555,6 +2554,7 @@ pg_tde_delete(Relation relation, ItemPointer tid,
bool all_visible_cleared = false;
HeapTuple old_key_tuple = NULL; /* replica identity of the tuple */
bool old_key_copied = false;
HeapTuple decrypted_tuple;

Assert(ItemPointerIsValid(tid));

Expand Down Expand Up @@ -2776,8 +2776,16 @@ pg_tde_delete(Relation relation, ItemPointer tid,
/*
* Compute replica identity tuple before entering the critical section so
* we don't PANIC upon a memory allocation failure.
*
* ExtractReplicaIdentity has to get a decrypted tuple, otherwise it
* won't be able to extract varlen attributes.
*/
old_key_tuple = ExtractReplicaIdentity(relation, &tp, true, &old_key_copied);
decrypted_tuple = heap_copytuple(&tp);
PG_TDE_DECRYPT_TUPLE(&tp, decrypted_tuple, GetRelationKey(relation->rd_locator));

old_key_tuple = ExtractReplicaIdentity(relation, decrypted_tuple, true, &old_key_copied);

pg_tde_freetuple(decrypted_tuple);

/*
* If this is the first possibly-multixact-able operation in the current
Expand Down

0 comments on commit 57cf804

Please sign in to comment.