Skip to content

Commit 443b9a4

Browse files
committed
MDEV-14929 - AddressSanitizer: memcpy-param-overlap in Field_longstr::compress
Handle overlaping "from" and Field_blob_compressed::value for compressed blobs similarily to regular blobs.
1 parent 69efa13 commit 443b9a4

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

mysql-test/main/column_compression.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,3 +1360,16 @@ SELECT a, LENGTH(a) FROM t1;
13601360
a LENGTH(a)
13611361
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 255
13621362
DROP TABLE t1;
1363+
#
1364+
# MDEV-14929 - AddressSanitizer: memcpy-param-overlap in
1365+
# Field_longstr::compress
1366+
#
1367+
CREATE TABLE t1(b BLOB COMPRESSED);
1368+
INSERT INTO t1 VALUES('foo'),('bar');
1369+
SET SESSION optimizer_switch = 'derived_merge=off';
1370+
SELECT * FROM ( SELECT * FROM t1 ) AS sq ORDER BY b;
1371+
b
1372+
bar
1373+
foo
1374+
SET SESSION optimizer_switch=DEFAULT;
1375+
DROP TABLE t1;

mysql-test/main/column_compression.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ INSERT INTO t1 VALUES(REPEAT('a', 255));
7979
SET column_compression_threshold=DEFAULT;
8080
SELECT a, LENGTH(a) FROM t1;
8181
DROP TABLE t1;
82+
83+
84+
--echo #
85+
--echo # MDEV-14929 - AddressSanitizer: memcpy-param-overlap in
86+
--echo # Field_longstr::compress
87+
--echo #
88+
CREATE TABLE t1(b BLOB COMPRESSED);
89+
INSERT INTO t1 VALUES('foo'),('bar');
90+
SET SESSION optimizer_switch = 'derived_merge=off';
91+
SELECT * FROM ( SELECT * FROM t1 ) AS sq ORDER BY b;
92+
SET SESSION optimizer_switch=DEFAULT;
93+
DROP TABLE t1;

sql/field.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8699,17 +8699,22 @@ int Field_blob_compressed::store(const char *from, size_t length,
86998699
{
87008700
ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED;
87018701
uint to_length= (uint)MY_MIN(max_data_length(), field_charset->mbmaxlen * length + 1);
8702+
String tmp(from, length, cs);
87028703
int rc;
87038704

8705+
if (from >= value.ptr() && from <= value.end() && tmp.copy(from, length, cs))
8706+
goto oom;
8707+
87048708
if (value.alloc(to_length))
8705-
{
8706-
set_ptr((uint32) 0, NULL);
8707-
return -1;
8708-
}
8709+
goto oom;
87098710

8710-
rc= compress((char*) value.ptr(), &to_length, from, (uint)length, cs);
8711+
rc= compress((char*) value.ptr(), &to_length, tmp.ptr(), (uint) length, cs);
87118712
set_ptr(to_length, (uchar*) value.ptr());
87128713
return rc;
8714+
8715+
oom:
8716+
set_ptr((uint32) 0, NULL);
8717+
return -1;
87138718
}
87148719

87158720

0 commit comments

Comments
 (0)