1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Don't copy uninitialized bytes when copying varstrings

When using field_conv(), which is called in case of field1=field2 copy in
fill_records(), full varstring's was copied, including unitialized bytes.
This caused valgrind to compilain about usage of unitialized bytes when
using Aria static length records.
Fixed by not using memcpy when copying varstrings but instead just copy
the real bytes.
This commit is contained in:
Monty
2019-08-14 23:46:47 +03:00
parent afe6eb499d
commit fa490e8022
5 changed files with 17 additions and 10 deletions

View File

@@ -7554,6 +7554,16 @@ int Field_varstring::save_field_metadata(uchar *metadata_ptr)
return 2; return 2;
} }
bool Field_varstring::memcpy_field_possible(const Field *from) const
{
return (Field_str::memcpy_field_possible(from) &&
!compression_method() == !from->compression_method() &&
length_bytes == ((Field_varstring*) from)->length_bytes &&
!(table->file->ha_table_flags() & HA_RECORD_MUST_BE_CLEAN_ON_WRITE));
}
int Field_varstring::store(const char *from,size_t length,CHARSET_INFO *cs) int Field_varstring::store(const char *from,size_t length,CHARSET_INFO *cs)
{ {
DBUG_ASSERT(marked_for_write_or_computed()); DBUG_ASSERT(marked_for_write_or_computed());

View File

@@ -3781,12 +3781,7 @@ public:
length_bytes : 0); length_bytes : 0);
} }
Copy_func *get_copy_func(const Field *from) const; Copy_func *get_copy_func(const Field *from) const;
bool memcpy_field_possible(const Field *from) const bool memcpy_field_possible(const Field *from) const;
{
return Field_str::memcpy_field_possible(from) &&
!compression_method() == !from->compression_method() &&
length_bytes == ((Field_varstring*) from)->length_bytes;
}
void update_data_type_statistics(Data_type_statistics *st) const void update_data_type_statistics(Data_type_statistics *st) const
{ {
st->m_variable_string_count++; st->m_variable_string_count++;

View File

@@ -212,7 +212,8 @@ enum enum_alter_inplace_result {
#define HA_HAS_NEW_CHECKSUM (1ULL << 38) #define HA_HAS_NEW_CHECKSUM (1ULL << 38)
#define HA_CAN_VIRTUAL_COLUMNS (1ULL << 39) #define HA_CAN_VIRTUAL_COLUMNS (1ULL << 39)
#define HA_MRR_CANT_SORT (1ULL << 40) #define HA_MRR_CANT_SORT (1ULL << 40)
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (1ULL << 41) /* unused */ /* All of VARCHAR is stored, including bytes after real varchar data */
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (1ULL << 41)
/* /*
This storage engine supports condition pushdown This storage engine supports condition pushdown

View File

@@ -1195,7 +1195,7 @@ int ha_maria::open(const char *name, int mode, uint test_if_locked)
that all bytes in the row is properly reset. that all bytes in the row is properly reset.
*/ */
if (file->s->data_file_type == STATIC_RECORD && if (file->s->data_file_type == STATIC_RECORD &&
(file->s->has_varchar_fields | file->s->has_null_fields)) (file->s->has_varchar_fields || file->s->has_null_fields))
int_table_flags|= HA_RECORD_MUST_BE_CLEAN_ON_WRITE; int_table_flags|= HA_RECORD_MUST_BE_CLEAN_ON_WRITE;
for (i= 0; i < table->s->keys; i++) for (i= 0; i < table->s->keys; i++)

View File

@@ -886,8 +886,9 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked)
the full row to ensure we don't get any errors from valgrind and the full row to ensure we don't get any errors from valgrind and
that all bytes in the row is properly reset. that all bytes in the row is properly reset.
*/ */
if ((file->s->options & HA_OPTION_PACK_RECORD) && if (!(file->s->options &
(file->s->has_varchar_fields | file->s->has_null_fields)) (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) &&
(file->s->has_varchar_fields || file->s->has_null_fields))
int_table_flags|= HA_RECORD_MUST_BE_CLEAN_ON_WRITE; int_table_flags|= HA_RECORD_MUST_BE_CLEAN_ON_WRITE;
for (i= 0; i < table->s->keys; i++) for (i= 0; i < table->s->keys; i++)