Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9035,10 +9035,13 @@ uint Field_blob::get_key_image_itRAW(const uchar *ptr_arg, uchar *buff,
{
size_t blob_length= get_length(ptr_arg);
const uchar *blob= get_ptr(ptr_arg);
size_t local_char_length= length / mbmaxlen();
local_char_length= field_charset()->charpos(blob, blob + blob_length,
local_char_length);
set_if_smaller(blob_length, local_char_length);
if (blob)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is not the only place where we call charpos function and if we were to do this kind of checks, we should be doing it in all other places too.
Fixing the root cause, i.e my_charpos_* set of functions to handle null seems like correct fix to me. thoughts @grooverdan ?

{
size_t local_char_length= length / mbmaxlen();
local_char_length= field_charset()->charpos(blob, blob + blob_length,
local_char_length);
set_if_smaller(blob_length, local_char_length);
}
Comment on lines +9038 to +9044

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of checking if (blob), it is more efficient and robust to check if (blob_length > 0). If the BLOB length is 0, there is no need to perform any character position calculations or division, as blob_length is already 0 and cannot be reduced further. This avoids redundant overhead for empty BLOBs and safely prevents passing NULL pointers to charpos.

  if (blob_length > 0)
  {
    size_t local_char_length= length / mbmaxlen();
    local_char_length= field_charset()->charpos(blob, blob + blob_length,
                                                local_char_length);
    set_if_smaller(blob_length, local_char_length);
  }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit clearer. Could DBUG_ASSERT(blob) in the block too.


if (length > blob_length)
{
Expand Down