Skip to content

Commit 8f0a97d

Browse files
committed
Fix segmentation fault in MergeInheritedAttribute()
While converting a pg_attribute tuple into a ColumnDef, ColumnDef::compression remains NULL if there is no compression method set fot the attribute. Calling strcmp() with NULL ColumnDef::compression, when comparing compression methods of parents, causes segmentation fault in MergeInheritedAttribute(). Skip comparing compression methods if either of them is NULL. Author: Ashutosh Bapat <[email protected]> Reported-by: Alexander Lakhin <[email protected]> Discussion: https://www.postgresql.org/message-id/b22a6834-aacb-7b18-0424-a3f5fe889667%40gmail.com
1 parent 91e7115 commit 8f0a97d

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/backend/commands/tablecmds.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -3432,12 +3432,16 @@ MergeInheritedAttribute(List *inh_columns,
34323432
*/
34333433
if (prevdef->compression == NULL)
34343434
prevdef->compression = newdef->compression;
3435-
else if (strcmp(prevdef->compression, newdef->compression) != 0)
3436-
ereport(ERROR,
3437-
(errcode(ERRCODE_DATATYPE_MISMATCH),
3438-
errmsg("column \"%s\" has a compression method conflict",
3439-
attributeName),
3440-
errdetail("%s versus %s", prevdef->compression, newdef->compression)));
3435+
else if (newdef->compression != NULL)
3436+
{
3437+
if (strcmp(prevdef->compression, newdef->compression) != 0)
3438+
ereport(ERROR,
3439+
(errcode(ERRCODE_DATATYPE_MISMATCH),
3440+
errmsg("column \"%s\" has a compression method conflict",
3441+
attributeName),
3442+
errdetail("%s versus %s",
3443+
prevdef->compression, newdef->compression)));
3444+
}
34413445

34423446
/*
34433447
* Check for GENERATED conflicts

src/test/regress/expected/compression.out

+7-3
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,18 @@ SELECT pg_column_compression(f1) FROM cmpart2;
223223
pglz
224224
(1 row)
225225

226-
-- test compression with inheritance, error
227-
CREATE TABLE cminh() INHERITS(cmdata, cmdata1);
226+
-- test compression with inheritance
227+
CREATE TABLE cminh() INHERITS(cmdata, cmdata1); -- error
228228
NOTICE: merging multiple inherited definitions of column "f1"
229229
ERROR: column "f1" has a compression method conflict
230230
DETAIL: pglz versus lz4
231-
CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata);
231+
CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); -- error
232232
NOTICE: merging column "f1" with inherited definition
233233
ERROR: column "f1" has a compression method conflict
234234
DETAIL: pglz versus lz4
235+
CREATE TABLE cmdata3(f1 text);
236+
CREATE TABLE cminh() INHERITS (cmdata, cmdata3);
237+
NOTICE: merging multiple inherited definitions of column "f1"
235238
-- test default_toast_compression GUC
236239
SET default_toast_compression = '';
237240
ERROR: invalid value for parameter "default_toast_compression": ""
@@ -251,6 +254,7 @@ INSERT INTO cmdata VALUES (repeat('123456789', 4004));
251254
f1 | text | | | | extended | lz4 | |
252255
Indexes:
253256
"idx" btree (f1)
257+
Child tables: cminh
254258

255259
SELECT pg_column_compression(f1) FROM cmdata;
256260
pg_column_compression

src/test/regress/sql/compression.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ INSERT INTO cmpart VALUES (repeat('123456789', 4004));
9393
SELECT pg_column_compression(f1) FROM cmpart1;
9494
SELECT pg_column_compression(f1) FROM cmpart2;
9595

96-
-- test compression with inheritance, error
97-
CREATE TABLE cminh() INHERITS(cmdata, cmdata1);
98-
CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata);
96+
-- test compression with inheritance
97+
CREATE TABLE cminh() INHERITS(cmdata, cmdata1); -- error
98+
CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); -- error
99+
CREATE TABLE cmdata3(f1 text);
100+
CREATE TABLE cminh() INHERITS (cmdata, cmdata3);
99101

100102
-- test default_toast_compression GUC
101103
SET default_toast_compression = '';

0 commit comments

Comments
 (0)