Commit 30894fe9 authored by Nikita Malyavin's avatar Nikita Malyavin

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.
parent 95fcd567
...@@ -1151,8 +1151,9 @@ class Field: public Value_source ...@@ -1151,8 +1151,9 @@ class Field: public Value_source
virtual void reset_fields() {} virtual void reset_fields() {}
const uchar *ptr_in_record(const uchar *record) const const uchar *ptr_in_record(const uchar *record) const
{ {
my_ptrdiff_t l_offset= (my_ptrdiff_t) (record - table->record[0]); my_ptrdiff_t l_offset= (my_ptrdiff_t) (ptr - table->record[0]);
return ptr + l_offset; DBUG_ASSERT(l_offset >= 0 && table->s->rec_buff_length - l_offset > 0);
return record + l_offset;
} }
virtual int set_default(); virtual int set_default();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment