Assert in pageinspect with NULL pages

From: Daria Lepikhova <d(dot)lepikhova(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Assert in pageinspect with NULL pages
Date: 2022-02-17 08:46:40
Message-ID: 561e187b-3549-c8d5-03f5-525c14e65bd0@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
0001-Add-checks-for-null-pages-to-pageinspect-functions.patch text/x-patch 10.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2022-02-17 08:48:03 Re: [PATCH] Fix out-of-bouds access (src/common/wchar.c)
Previous Message Kyotaro Horiguchi 2022-02-17 08:24:58 Re: [PATCH] Fix out-of-bouds access (src/common/wchar.c)