mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-20 18:23:23 +02:00
Block numbers are 32-bit unsigned integers. Therefore, the smallest SQL integer type that they can fit in is bigint. However, in the pageinspect module, most input and output parameters dealing with block numbers were declared as int. The behavior with block numbers larger than a signed 32-bit integer was therefore dubious. Change these arguments to type bigint and add some more explicit error checking on the block range. (Other contrib modules appear to do this correctly already.) Since we are changing argument types of existing functions, in order to not misbehave if the binary is updated before the extension is updated, we need to create new C symbols for the entry points, similar to how it's done in other extensions as well. Reported-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/d8f6bdd536df403b9b33816e9f7e0b9d@G08CNEXMBPEKD05.g08.fujitsu.local
74 lines
2.0 KiB
Plaintext
74 lines
2.0 KiB
Plaintext
CREATE TABLE test1 (a int8, b text);
|
|
INSERT INTO test1 VALUES (72057594037927937, 'text');
|
|
CREATE INDEX test1_a_idx ON test1 USING btree (a);
|
|
\x
|
|
SELECT * FROM bt_metap('test1_a_idx');
|
|
-[ RECORD 1 ]-----------+-------
|
|
magic | 340322
|
|
version | 4
|
|
root | 1
|
|
level | 0
|
|
fastroot | 1
|
|
fastlevel | 0
|
|
oldest_xact | 0
|
|
last_cleanup_num_tuples | -1
|
|
allequalimage | t
|
|
|
|
SELECT * FROM bt_page_stats('test1_a_idx', -1);
|
|
ERROR: invalid block number
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 0);
|
|
ERROR: block 0 is a meta page
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 1);
|
|
-[ RECORD 1 ]-+-----
|
|
blkno | 1
|
|
type | l
|
|
live_items | 1
|
|
dead_items | 0
|
|
avg_item_size | 16
|
|
page_size | 8192
|
|
free_size | 8128
|
|
btpo_prev | 0
|
|
btpo_next | 0
|
|
btpo | 0
|
|
btpo_flags | 3
|
|
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 2);
|
|
ERROR: block number out of range
|
|
SELECT * FROM bt_page_items('test1_a_idx', -1);
|
|
ERROR: invalid block number
|
|
SELECT * FROM bt_page_items('test1_a_idx', 0);
|
|
ERROR: block 0 is a meta page
|
|
SELECT * FROM bt_page_items('test1_a_idx', 1);
|
|
-[ RECORD 1 ]-----------------------
|
|
itemoffset | 1
|
|
ctid | (0,1)
|
|
itemlen | 16
|
|
nulls | f
|
|
vars | f
|
|
data | 01 00 00 00 00 00 00 01
|
|
dead | f
|
|
htid | (0,1)
|
|
tids |
|
|
|
|
SELECT * FROM bt_page_items('test1_a_idx', 2);
|
|
ERROR: block number out of range
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', -1));
|
|
ERROR: invalid block number
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 0));
|
|
ERROR: block is a meta page
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 1));
|
|
-[ RECORD 1 ]-----------------------
|
|
itemoffset | 1
|
|
ctid | (0,1)
|
|
itemlen | 16
|
|
nulls | f
|
|
vars | f
|
|
data | 01 00 00 00 00 00 00 01
|
|
dead | f
|
|
htid | (0,1)
|
|
tids |
|
|
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 2));
|
|
ERROR: block number 2 is out of range for relation "test1_a_idx"
|
|
DROP TABLE test1;
|