Commit 0eca30a7 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-21749: page_cur_insert_rec_low(): Assertion rdm - rd + bd <= insert_buf + rec_size failed.

This bug was introduced in
commit 7ae21b18
(the main commit of MDEV-12353).

page_cur_insert_rec_low(): Before entering the comparison loop, make sure
that the range does not exceed c_end already at the start of the loop.
The loop is only comparing for pointer equality, and that condition
cdm == c_end would never hold if the end was already exceeded in
the beginning. Also, skip the comparison altogether if we could find
at most 2 equal bytes.

PageBulk::insertPage(): Apply a similar change. It seems that this
code was correct, because the loop checks for cdm < c_end.
parent 956e12d6
...@@ -275,6 +275,8 @@ inline void PageBulk::insertPage(rec_t *rec, offset_t *offsets) ...@@ -275,6 +275,8 @@ inline void PageBulk::insertPage(rec_t *rec, offset_t *offsets)
goto no_data; goto no_data;
/* Try to copy any data bytes of the preceding record. */ /* Try to copy any data bytes of the preceding record. */
if (c_end - cd > 2)
{
const byte *cdm= cd; const byte *cdm= cd;
const byte *rdm= rd; const byte *rdm= rd;
for (; cdm < c_end && *rdm == *cdm; cdm++, rdm++) for (; cdm < c_end && *rdm == *cdm; cdm++, rdm++)
...@@ -291,6 +293,7 @@ inline void PageBulk::insertPage(rec_t *rec, offset_t *offsets) ...@@ -291,6 +293,7 @@ inline void PageBulk::insertPage(rec_t *rec, offset_t *offsets)
r= rdm; r= rdm;
} }
} }
}
if (size_t len= static_cast<size_t>(insert_rec_end - b)) if (size_t len= static_cast<size_t>(insert_rec_end - b))
m_mtr.memcpy<mtr_t::FORCED>(*m_block, b, r, len); m_mtr.memcpy<mtr_t::FORCED>(*m_block, b, r, len);
......
...@@ -1342,6 +1342,8 @@ page_cur_insert_rec_low( ...@@ -1342,6 +1342,8 @@ page_cur_insert_rec_low(
/* Try to copy any data bytes of the preceding record. */ /* Try to copy any data bytes of the preceding record. */
const byte * const cd= cur->rec + (rd - rec); const byte * const cd= cur->rec + (rd - rec);
if (c_end - cd > 2)
{
const byte *cdm= cd; const byte *cdm= cd;
const byte *rdm= rd; const byte *rdm= rd;
while (*rdm++ == *cdm++) while (*rdm++ == *cdm++)
...@@ -1362,6 +1364,7 @@ page_cur_insert_rec_low( ...@@ -1362,6 +1364,7 @@ page_cur_insert_rec_low(
} }
} }
} }
}
if (size_t len= static_cast<size_t>(insert_buf + rec_size - b)) if (size_t len= static_cast<size_t>(insert_buf + rec_size - b))
mtr->memcpy<mtr_t::FORCED>(*block, b, r, len); mtr->memcpy<mtr_t::FORCED>(*block, b, r, len);
......
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