1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-09 22:24:09 +03:00

Add DBUG_ASSERT in Field::ptr_in_record

1. Subtracting table->record[0] from record is UB (non-contiguous buffers)
2. It is very popular to use move_field_offset, which changes Field::ptr,
but leaves table->record[0] unchanged. This makes a ptr_in_record result
incorrect, since it relies on table->record[0] value.
The check ensures the result is within the queried record boundaries.
This commit is contained in:
Nikita Malyavin
2020-09-22 20:17:02 +10:00
parent 95fcd567bd
commit 30894fe9a9

View File

@@ -1151,8 +1151,9 @@ public:
virtual void reset_fields() {}
const uchar *ptr_in_record(const uchar *record) const
{
my_ptrdiff_t l_offset= (my_ptrdiff_t) (record - table->record[0]);
return ptr + l_offset;
my_ptrdiff_t l_offset= (my_ptrdiff_t) (ptr - table->record[0]);
DBUG_ASSERT(l_offset >= 0 && table->s->rec_buff_length - l_offset > 0);
return record + l_offset;
}
virtual int set_default();