From 52de0a885eb1bbfdaa1f03f5352419a124c8f419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=81opusza=C5=84ski?= Date: Tue, 3 Mar 2026 13:12:29 +0100 Subject: [PATCH] Bug#39033858 Parallel_reader::Scan_ctx::copy_row copies wrong range of bytes Problem: InnoDB uses a convention where rec pointers point in between two fragments of the record: to the left of it, are so called "extra" bytes which contain metadata such as flags, info about which fields are null and what is their length. To the right of it, is the actual data of the fields. The function rec_offs_size(offsets) returns the total length of the record which is the sum of these two: ``` rec_offs_data_size(offsets) + rec_offs_extra_size(offsets) ``` The logic of Parallel_reader::Scan_ctx::copy_row() copied that many bytes into a freshly allocated buffer, but used rec address as the source, instead of "rec - extra", resulting in copying wrong range of bytes. Solution: Adjust the logic to copy the correct range of bytes. Change-Id: Ia0463e4a752dfce70ff5a2ac83818132de9a638c --- storage/innobase/row/row0pread.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/storage/innobase/row/row0pread.cc b/storage/innobase/row/row0pread.cc index 169cdfd8dda..0114fdcb824 100644 --- a/storage/innobase/row/row0pread.cc +++ b/storage/innobase/row/row0pread.cc @@ -489,9 +489,14 @@ void Parallel_reader::Scan_ctx::copy_row(const rec_t *rec, Iter *iter) const { auto copy_rec = static_cast(mem_heap_alloc(iter->m_heap, rec_len)); - memcpy(copy_rec, rec, rec_len); - - iter->m_rec = copy_rec; + /* In InnoDB rec_t points after the extra bytes. */ + const auto extra = rec_offs_extra_size(iter->m_offsets); + ut_ad(extra <= rec_len); + + memcpy(copy_rec, rec - extra, rec_len); + /* Even though we (by convention) point after extra bytes, all of them + will be freed, as instead of free(iter->m_rec) we use mem_heap_empty(). */ + iter->m_rec = copy_rec + extra; auto tuple = row_rec_to_index_entry_low(iter->m_rec, m_config.m_index, iter->m_offsets, iter->m_heap);