Commit 36c01167 authored by Jan Lindström's avatar Jan Lindström

MDEV-12632: Source and destination overlap in memcpy,...

MDEV-12632: Source and destination overlap in memcpy, encryption.innodb-discard-import-change fails in buildbot with valgrind

Problem was that if tablespace was encrypted we try to copy
also page 0 from read buffer to write buffer that are in
that case the same memory area.

fil_iterate
	When tablespace is encrypted or compressed its
        first page (i.e. page 0) is not encrypted or
	compressed and there is no need to copy buffer.
parent 2f1f1609
...@@ -3349,12 +3349,12 @@ fil_iterate( ...@@ -3349,12 +3349,12 @@ fil_iterate(
bool updated = false; bool updated = false;
os_offset_t page_off = offset; os_offset_t page_off = offset;
ulint n_pages_read = n_bytes / size; ulint n_pages_read = n_bytes / size;
bool decrypted = false;
block->page.id.set_page_no(ulint(page_off / size)); block->page.id.set_page_no(ulint(page_off / size));
for (ulint i = 0; i < n_pages_read; for (ulint i = 0; i < n_pages_read;
block->page.id.set_page_no(block->page.id.page_no() + 1), block->page.id.set_page_no(block->page.id.page_no() + 1),
++i, page_off += size, block->frame += size) { ++i, page_off += size, block->frame += size) {
bool decrypted = false;
err = DB_SUCCESS; err = DB_SUCCESS;
byte* src = readptr + i * size; byte* src = readptr + i * size;
byte* dst = io_buffer + i * size; byte* dst = io_buffer + i * size;
...@@ -3401,6 +3401,7 @@ fil_iterate( ...@@ -3401,6 +3401,7 @@ fil_iterate(
block->frame = src; block->frame = src;
frame_changed = true; frame_changed = true;
} else { } else {
ut_ad(dst != src);
memcpy(dst, src, size); memcpy(dst, src, size);
} }
} }
...@@ -3460,9 +3461,13 @@ fil_iterate( ...@@ -3460,9 +3461,13 @@ fil_iterate(
ut_ad(encrypted ? ut_ad(encrypted ?
src != dst && dst != writeptr + (i * size):1); src != dst && dst != writeptr + (i * size):1);
if (encrypted) { /* When tablespace is encrypted or compressed its
memcpy(writeptr + (i * size), first page (i.e. page 0) is not encrypted or
callback.get_frame(block), size); compressed and there is no need to copy frame. */
if (encrypted && i != 0) {
byte *local_frame = callback.get_frame(block);
ut_ad((writeptr + (i * size)) != local_frame);
memcpy((writeptr + (i * size)), local_frame, size);
} }
if (frame_changed) { if (frame_changed) {
...@@ -3500,6 +3505,7 @@ fil_iterate( ...@@ -3500,6 +3505,7 @@ fil_iterate(
if (tmp == src) { if (tmp == src) {
/* TODO: remove unnecessary memcpy's */ /* TODO: remove unnecessary memcpy's */
ut_ad(dest != src);
memcpy(dest, src, size); memcpy(dest, src, size);
} }
......
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