Skip to content

Commit 9c42b90

Browse files
author
Jan Lindström
committed
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.
1 parent 9124590 commit 9c42b90

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

storage/innobase/row/row0import.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,12 +3348,12 @@ fil_iterate(
33483348
bool updated = false;
33493349
os_offset_t page_off = offset;
33503350
ulint n_pages_read = n_bytes / size;
3351-
bool decrypted = false;
33523351
block->page.id.set_page_no(ulint(page_off / size));
33533352

33543353
for (ulint i = 0; i < n_pages_read;
33553354
block->page.id.set_page_no(block->page.id.page_no() + 1),
33563355
++i, page_off += size, block->frame += size) {
3356+
bool decrypted = false;
33573357
err = DB_SUCCESS;
33583358
byte* src = readptr + i * size;
33593359
byte* dst = io_buffer + i * size;
@@ -3400,6 +3400,7 @@ fil_iterate(
34003400
block->frame = src;
34013401
frame_changed = true;
34023402
} else {
3403+
ut_ad(dst != src);
34033404
memcpy(dst, src, size);
34043405
}
34053406
}
@@ -3459,9 +3460,13 @@ fil_iterate(
34593460
ut_ad(encrypted ?
34603461
src != dst && dst != writeptr + (i * size):1);
34613462

3462-
if (encrypted) {
3463-
memcpy(writeptr + (i * size),
3464-
callback.get_frame(block), size);
3463+
/* When tablespace is encrypted or compressed its
3464+
first page (i.e. page 0) is not encrypted or
3465+
compressed and there is no need to copy frame. */
3466+
if (encrypted && i != 0) {
3467+
byte *local_frame = callback.get_frame(block);
3468+
ut_ad((writeptr + (i * size)) != local_frame);
3469+
memcpy((writeptr + (i * size)), local_frame, size);
34653470
}
34663471

34673472
if (frame_changed) {
@@ -3499,6 +3504,7 @@ fil_iterate(
34993504

35003505
if (tmp == src) {
35013506
/* TODO: remove unnecessary memcpy's */
3507+
ut_ad(dest != src);
35023508
memcpy(dest, src, size);
35033509
}
35043510

0 commit comments

Comments
 (0)