Skip to content

Commit a65623b

Browse files
committed
MDEV-11883 MariaDB crashes with out-of-memory when query information_schema
CSV engine didn't expect CSM files to be read-only
1 parent 71b4503 commit a65623b

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

mysql-test/suite/csv/read_only.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
create table t1 (a int not null) engine=csv;
2+
insert t1 values (1),(2);
3+
flush tables;
4+
select * from information_schema.tables where table_schema='test';
5+
TABLE_CATALOG def
6+
TABLE_SCHEMA test
7+
TABLE_NAME t1
8+
TABLE_TYPE BASE TABLE
9+
ENGINE NULL
10+
VERSION NULL
11+
ROW_FORMAT NULL
12+
TABLE_ROWS NULL
13+
AVG_ROW_LENGTH NULL
14+
DATA_LENGTH NULL
15+
MAX_DATA_LENGTH NULL
16+
INDEX_LENGTH NULL
17+
DATA_FREE NULL
18+
AUTO_INCREMENT NULL
19+
CREATE_TIME NULL
20+
UPDATE_TIME NULL
21+
CHECK_TIME NULL
22+
TABLE_COLLATION NULL
23+
CHECKSUM NULL
24+
CREATE_OPTIONS NULL
25+
TABLE_COMMENT File './test/t1.CSM' not found (Errcode: 13 "Permission denied")
26+
Warnings:
27+
Level Warning
28+
Code 29
29+
Message File './test/t1.CSM' not found (Errcode: 13 "Permission denied")
30+
drop table t1;

mysql-test/suite/csv/read_only.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# MDEV-11883 MariaDB crashes with out-of-memory when query information_schema
3+
#
4+
source include/have_csv.inc;
5+
6+
let datadir=`select @@datadir`;
7+
8+
create table t1 (a int not null) engine=csv;
9+
insert t1 values (1),(2);
10+
flush tables;
11+
12+
chmod 0400 $datadir/test/t1.CSM;
13+
chmod 0400 $datadir/test/t1.CSV;
14+
15+
--replace_result $datadir ./
16+
query_vertical select * from information_schema.tables where table_schema='test';
17+
18+
drop table t1;
19+

storage/csv/ha_tina.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int read_meta_file(File meta_file, ha_rows *rows)
289289
mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0));
290290
if (mysql_file_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0)
291291
!= META_BUFFER_SIZE)
292-
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
292+
DBUG_RETURN(my_errno= HA_ERR_CRASHED_ON_USAGE);
293293

294294
/*
295295
Parse out the meta data, we ignore version at the moment
@@ -418,10 +418,13 @@ static int free_share(TINA_SHARE *share)
418418
int result_code= 0;
419419
if (!--share->use_count){
420420
/* Write the meta file. Mark it as crashed if needed. */
421-
(void)write_meta_file(share->meta_file, share->rows_recorded,
422-
share->crashed ? TRUE :FALSE);
423-
if (mysql_file_close(share->meta_file, MYF(0)))
424-
result_code= 1;
421+
if (share->meta_file != -1)
422+
{
423+
(void)write_meta_file(share->meta_file, share->rows_recorded,
424+
share->crashed ? TRUE :FALSE);
425+
if (mysql_file_close(share->meta_file, MYF(0)))
426+
result_code= 1;
427+
}
425428
if (share->tina_write_opened)
426429
{
427430
if (mysql_file_close(share->tina_write_filedes, MYF(0)))
@@ -930,7 +933,7 @@ int ha_tina::open(const char *name, int mode, uint open_options)
930933
if (share->crashed && !(open_options & HA_OPEN_FOR_REPAIR))
931934
{
932935
free_share(share);
933-
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
936+
DBUG_RETURN(my_errno ? my_errno : HA_ERR_CRASHED_ON_USAGE);
934937
}
935938

936939
local_data_file_version= share->data_file_version;

0 commit comments

Comments
 (0)