Commit 6151adaa authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-20865 extra2_write_len() fix

Current implementation of extra2_write_len() does not guarantee of
writing correct 2-byte values as it skips writing zero at the
beginning.

Refined DBUG_ASSERT() to more truthful limit.
parent bbd7d943
...@@ -73,6 +73,11 @@ enum extra2_index_flags ...@@ -73,6 +73,11 @@ enum extra2_index_flags
EXTRA2_IGNORED_KEY EXTRA2_IGNORED_KEY
}; };
#define FRM_HEADER_SIZE 64
#define FRM_FORMINFO_SIZE 288
#define FRM_MAX_SIZE (1024*1024)
inline size_t extra2_read_len(const uchar **pos, const uchar *end) inline size_t extra2_read_len(const uchar **pos, const uchar *end)
{ {
size_t length= *(*pos)++; size_t length= *(*pos)++;
...@@ -91,10 +96,10 @@ inline size_t extra2_read_len(const uchar **pos, const uchar *end) ...@@ -91,10 +96,10 @@ inline size_t extra2_read_len(const uchar **pos, const uchar *end)
/* /*
write the length as write the length as
if ( 0 < length <= 255) one byte if ( 0 < length <= 255) one byte
if (256 < length <= 65535) zero byte, then two bytes, low-endian if (256 < length < ~65535) zero byte, then two bytes, low-endian
*/ */
inline inline uchar *
uchar *extra2_write_len(uchar *pos, size_t len) extra2_write_len(uchar *pos, size_t len)
{ {
DBUG_ASSERT(len); DBUG_ASSERT(len);
if (len <= 255) if (len <= 255)
...@@ -104,10 +109,19 @@ uchar *extra2_write_len(uchar *pos, size_t len) ...@@ -104,10 +109,19 @@ uchar *extra2_write_len(uchar *pos, size_t len)
/* /*
At the moment we support options_len up to 64K. At the moment we support options_len up to 64K.
We can easily extend it in the future, if the need arises. We can easily extend it in the future, if the need arises.
See build_frm_image():
int2store(frm_header + 6, frm.length);
frm.length includes FRM_HEADER_SIZE + extra2_size + 4
and it must be 2 bytes, therefore extra2_size cannot be more than
0xFFFF - FRM_HEADER_SIZE - 4.
*/ */
DBUG_ASSERT(len <= 65535); DBUG_ASSERT(len <= 0xffff - FRM_HEADER_SIZE - 4);
int2store(pos + 1, len); *pos++= 0;
pos+= 3; int2store(pos, len);
pos+= 2;
} }
return pos; return pos;
} }
......
...@@ -168,10 +168,6 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table, ...@@ -168,10 +168,6 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
List<Create_field> &create_fields, List<Create_field> &create_fields,
uint keys, KEY *key_info, handler *db_file); uint keys, KEY *key_info, handler *db_file);
#define FRM_HEADER_SIZE 64
#define FRM_FORMINFO_SIZE 288
#define FRM_MAX_SIZE (1024*1024)
static inline bool is_binary_frm_header(const uchar *head) static inline bool is_binary_frm_header(const uchar *head)
{ {
return head[0] == 254 return head[0] == 254
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment