Skip to content

Commit 561b5ce

Browse files
dr-mvuvova
authored andcommitted
MDEV-21748 ASAN use-after-poison in PageBulk::insertPage()
PageBulk::insertPage(): Check the array bounds before comparing. We used to read one byte beyond the end of the 'rec' payload. The incorrect logic was originally introduced in commit 7ae21b1.
1 parent e2e2f89 commit 561b5ce

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

mysql-test/suite/innodb/r/alter_table.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ t2 CREATE TABLE `t2` (
6868
alter table t1 engine=innodb;
6969
alter table t1 add column b int;
7070
drop table t1,t2;
71+
#
72+
# MDEV-21748 ASAN use-after-poison in PageBulk::insertPage()
73+
#
74+
CREATE TABLE t1 (pk TIMESTAMP PRIMARY KEY, a TIMESTAMP NULL UNIQUE)
75+
ENGINE=InnoDB;
76+
INSERT INTO t1 VALUES
77+
('2020-03-10 10:21:00', NULL),
78+
('0000-00-00 00:00:00', '0000-00-00 00:00:00');
79+
ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
80+
DROP TABLE t1;

mysql-test/suite/innodb/t/alter_table.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,14 @@ show create table t2;
7171
alter table t1 engine=innodb;
7272
alter table t1 add column b int;
7373
drop table t1,t2;
74+
75+
--echo #
76+
--echo # MDEV-21748 ASAN use-after-poison in PageBulk::insertPage()
77+
--echo #
78+
CREATE TABLE t1 (pk TIMESTAMP PRIMARY KEY, a TIMESTAMP NULL UNIQUE)
79+
ENGINE=InnoDB;
80+
INSERT INTO t1 VALUES
81+
('2020-03-10 10:21:00', NULL),
82+
('0000-00-00 00:00:00', '0000-00-00 00:00:00');
83+
ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
84+
DROP TABLE t1;

storage/innobase/btr/btr0bulk.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ inline void PageBulk::insertPage(rec_t *rec, offset_t *offsets)
270270
byte *bd= insert_rec;
271271
const byte *rd= rec;
272272
/* Skip any unchanged prefix of the record. */
273-
for (; *bd == *rd; cd++, bd++, rd++)
273+
for (;; cd++, bd++, rd++)
274274
if (bd == insert_rec_end)
275275
goto no_data;
276+
else if (*bd != *rd)
277+
break;
276278

277279
/* Try to copy any data bytes of the preceding record. */
278280
if (c_end - cd > 2)

0 commit comments

Comments
 (0)