Skip to content

[#1805] walinfo: Don't copy offset arrays past fixed-size record wrappers - #1806

Open
rythmlongia wants to merge 1 commit into
pgmoneta:mainfrom
rythmlongia:walinfo-offsets-overflow
Open

rythmlongia wants to merge 1 commit into
pgmoneta:mainfrom
rythmlongia:walinfo-offsets-overflow

Conversation

@rythmlongia

Copy link
Copy Markdown
Contributor

Fixes #1805.

create_spg_xlog_vacuum_redirect(), create_gist_xlog_delete() and create_xl_hash_vacuum_one_page() allocate their wrappers with malloc(sizeof(...)), which leaves no room for the offsets[FLEXIBLE_ARRAY_MEMBER] array. The parsers then copied the whole array from the record, writing past the allocation as soon as the array didn't fit in the struct's padding (4 or more entries for SP-GiST VACUUM_REDIRECT).

offsets is never read: the format functions don't print it, and the wrapper is freed right after formatting. This removes the four copies:

  • pgmoneta_wal_parse_spg_xlog_vacuum_redirect_v15 / _v16 (rm_spgist.c)
  • pgmoneta_wal_parse_gist_xlog_delete_v16 (rm_gist.c)
  • pgmoneta_wal_parse_xl_hash_vacuum_one_page_v16 (rm_hash.c)

Testing on PostgreSQL 16 WAL with an SP-GiST index after DELETE/UPDATE/VACUUM (two segments, ASan build):

before after
AddressSanitizer errors heap-buffer-overflow in rm_spgist.c none
records shown by walinfo (pg_waldump: 170468) 144345 170468

The output for all records now matches pg_waldump in count and LSNs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

walinfo: heap-buffer-overflow when parsing SP-GiST VACUUM_REDIRECT records (same pattern in GiST DELETE and Hash VACUUM_ONE_PAGE)

1 participant