Skip to content

Commit

Permalink
MENT-1703 Repeatable crash during backup after processing very large …
Browse files Browse the repository at this point in the history
…ibdata1

The crash happened in filename_to_spacename() when using it on a
filename that is not in the format of "./database/table.ibd".
According to Marko, it is possible the function is called with
the path to an undo file, which would cause a crash.

This patch fixes this by,  instead of crashing with unexpected filenames,
returning them 'as such', except for changing all '\' to '/'.
  • Loading branch information
montywi committed May 24, 2023
1 parent 7737f15 commit d77d9e1
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions extra/mariabackup/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,28 +851,49 @@ void mdl_lock_all()


// Convert non-null terminated filename to space name
// Note that in 10.6 the filename may be an undo file name
static std::string filename_to_spacename(const void *filename, size_t len)
{
// null- terminate filename
char *f = (char *)malloc(len + 1);
ut_a(f);
memcpy(f, filename, len);
f[len] = 0;
for (size_t i = 0; i < len; i++)
if (f[i] == '\\')
f[i] = '/';
char *p = strrchr(f, '.');
ut_a(p);
*p = 0;
char *table = strrchr(f, '/');
ut_a(table);
*table = 0;
char *db = strrchr(f, '/');
ut_a(db);
*table = '/';
std::string s(db+1);
free(f);
return s;
char f[FN_REFLEN];
char *p= 0, *table, *db;
DBUG_ASSERT(len = FN_REFLEN);

strmake(f, (const char*) filename, len);

#ifdef _WIN32
for (size_t i = 0; i < len; i++)
{
if (f[i] == '\\')
f[i] = '/';
}
#endif

/* Remove extension, if exists */
if (!(p= strrchr(f, '.')))
goto err;
*p= 0;

/* Find table name */
if (!(table= strrchr(f, '/')))
goto err;
*table = 0;

/* Find database name */
db= strrchr(f, '/');
*table = '/';
if (!db)
goto err;
{
std::string s(db+1);
return s;
}

err:
/* Not a database/table. Return original (converted) name */
if (p)
*p= '.'; // Restore removed extension
std::string s(f);
return s;
}

/** Report an operation to create, delete, or rename a file during backup.
Expand Down

0 comments on commit d77d9e1

Please sign in to comment.