Tighten magic_number_guess_fourcc TGA heuristic

Prior to this commit, test/data/cbor-rfc-7049-examples.cbor was
incorrectly sniffed as TGA. /usr/bin/file did this too.

$ file test/data/cbor-rfc-7049-examples.cbor
test/data/cbor-rfc-7049-examples.cbor: Targa image data - Map 59395 x 26
x 15 +6169 +6500 - 2-bit alpha - interleave "@\033"

Updates #67
This commit is contained in:
Nigel Tao committed 2022-01-15 14:32:51 +11:00
1 parent ed4d556721
commit c82793a984
2 files changed
+14 -6

No files matched your search

+7 -3
View File
@@ -90,12 +90,12 @@ wuffs_base__magic_number_guess_fourcc__maybe_tga(
return 0; return 0;
} }
// Allow-list for the Color Map Entry Size field. // Allow-list for the Color Map Entry Size field (if the Color Map Type field
// is non-zero) or else all the Color Map fields should be zero.
if (prefix_data.len < 8) { if (prefix_data.len < 8) {
return prefix_closed ? 0 : -1; return prefix_closed ? 0 : -1;
} } else if (prefix_data.ptr[1] != 0x00) {
switch (prefix_data.ptr[7]) { switch (prefix_data.ptr[7]) {
case 0x00:
case 0x0F: case 0x0F:
case 0x10: case 0x10:
case 0x18: case 0x18:
@@ -104,6 +104,10 @@ wuffs_base__magic_number_guess_fourcc__maybe_tga(
default: default:
return 0; return 0;
} }
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
return 0;
}
// Allow-list for the Pixel Depth field. // Allow-list for the Pixel Depth field.
if (prefix_data.len < 17) { if (prefix_data.len < 17) {
+7 -3
View File
@@ -16012,12 +16012,12 @@ wuffs_base__magic_number_guess_fourcc__maybe_tga(
return 0; return 0;
} }
// Allow-list for the Color Map Entry Size field. // Allow-list for the Color Map Entry Size field (if the Color Map Type field
// is non-zero) or else all the Color Map fields should be zero.
if (prefix_data.len < 8) { if (prefix_data.len < 8) {
return prefix_closed ? 0 : -1; return prefix_closed ? 0 : -1;
} } else if (prefix_data.ptr[1] != 0x00) {
switch (prefix_data.ptr[7]) { switch (prefix_data.ptr[7]) {
case 0x00:
case 0x0F: case 0x0F:
case 0x10: case 0x10:
case 0x18: case 0x18:
@@ -16026,6 +16026,10 @@ wuffs_base__magic_number_guess_fourcc__maybe_tga(
default: default:
return 0; return 0;
} }
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
return 0;
}
// Allow-list for the Pixel Depth field. // Allow-list for the Pixel Depth field.
if (prefix_data.len < 17) { if (prefix_data.len < 17) {