libheif
libheif copied to clipboard
heif_check_filetype returns heif_filetype_maybe incorrectly?
It seems that heif_check_filetype
returns heif_filetype_maybe
when the header is too small? Is this correct?
Shouldn't this code
heif_filetype_result heif_check_filetype(const uint8_t* data, int len)
{
if (len < 8) {
return heif_filetype_maybe;
}
if (data[4] != 'f' ||
data[5] != 't' ||
data[6] != 'y' ||
data[7] != 'p') {
return heif_filetype_no;
}
if (len >= 12) {
heif_brand brand = heif_main_brand(data, len);
if (brand == heif_heic) {
return heif_filetype_yes_supported;
}
else if (brand == heif_heix) {
return heif_filetype_yes_supported;
}
else if (brand == heif_avif) {
return heif_filetype_yes_supported;
}
else if (brand == heif_unknown_brand) {
return heif_filetype_no;
}
else if (brand == heif_mif1) {
return heif_filetype_maybe;
}
else {
return heif_filetype_yes_unsupported;
}
}
return heif_filetype_maybe;
}
become like this
heif_filetype_result heif_check_filetype(const uint8_t* data, int len)
{
if (len < 12) {
return heif_filetype_no;
}
if (data[4] != 'f' ||
data[5] != 't' ||
data[6] != 'y' ||
data[7] != 'p') {
return heif_filetype_no;
}
heif_brand brand = heif_main_brand(data, len);
switch (brand) {
case heif_heix:
case heif_avif:
return heif_filetype_yes_supported;
case heif_mif1:
return heif_filetype_maybe;
case heif_unknown_brand:
return heif_filetype_no;
default:
return heif_filetype_yes_unsupported;
}
}
The original code looks good to me. It returns 'maybe' if the provided data is not enough to know and 'no'/'yes' if it can make a decision.
Are you sure? It returns heif_filetype_maybe
when the file is only 8 bytes long. Surely that can't be a valid HEIF file?
len
is not the total file size, but the number of bytes from the beginning that are considered for the check.
Okay got it, closing