Assert in pageinspect with NULL pages - Mailing list pgsql-hackers

From Daria Lepikhova
Subject Assert in pageinspect with NULL pages
Date
Msg-id 561e187b-3549-c8d5-03f5-525c14e65bd0@postgrespro.ru
Whole thread Raw
Responses Re: Assert in pageinspect with NULL pages  (Michael Paquier <michael@paquier.xyz>)
Re: Assert in pageinspect with NULL pages  (Justin Pryzby <pryzby@telsasoft.com>)
List pgsql-hackers
Hi, hackers!

If we trying to call pageinspect functions for pages which are filled 
with nulls, we will get core dump. It happens with null pages for all 
indexes in pageinspect and for page_checksum. This problem was founded 
firstly by Anastasia Lubennikova, and now I continue this task.

For example, next script leads to fail.
CREATE TABLE test1 (
     x bigserial,
     y bigint DEFAULT 0
);
INSERT INTO test1(y) SELECT 0 FROM generate_series(1,1E6) AS x;
SELECT page_checksum(repeat(E'\\000', 8192)::bytea, 1);

server closed the connection unexpectedly
     This probably means the server terminated abnormally
     before or while processing the request.
fatal: connection to server was lost
LOG:  server process (PID 16465) was terminated by signal 6
DETAIL:  Failed process was running: select 
page_checksum(repeat(E'\\000', 8192)::bytea, 1);
LOG:  terminating any other active server processes
LOG:  all server processes terminated; reinitializing
LOG:  database system was interrupted; last known up at 2022-02-16 
14:03:16 +05
LOG:  database system was not properly shut down; automatic recovery in 
progress
LOG:  redo starts at 0/14F1B20
LOG:  invalid record length at 0/5D40CD8: wanted 24, got 0
LOG:  redo done at 0/5D40BC0 system usage: CPU: user: 0.98 s, system: 
0.02 s, elapsed: 1.01 s
LOG:  checkpoint starting: end-of-recovery immediate wait
LOG:  checkpoint complete: wrote 5500 buffers (33.6%); 0 WAL file(s) 
added, 0 removed, 4 recycled; write=0.064 s, sync=0.007 s, total=0.080 
s; sync files=45, longest=0.004 s, average=0.001 s; distance=74044 kB, 
estimate=74044 kB
LOG:  database system is ready to accept connections

Also it is possible to use
     select brin_metapage_info(repeat(E'\\000', 8192)::bytea);
or
     select bt_page_items(repeat(E'\\000', 8192)::bytea);
for getting fail.

I tried to make some additional checks for null pages into pageinspect' 
functions. The attached patch also contains tests for this case.
What do you think?

-- 
Daria Lepikhova
Postgres Professional

Attachment

pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: [PATCH] Fix out-of-bouds access (src/common/wchar.c)
Next
From: Julien Rouhaud
Date:
Subject: Re: [PATCH] Fix out-of-bouds access (src/common/wchar.c)