1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

common: Detect PNG and JPEG file formats.

* common/miscellaneous.c (is_file_compressed): Add detect code.
--

GnuPG-bug-id: 6332
This commit is contained in:
Werner Koch 2023-01-19 11:27:25 +01:00
parent ce8ffd71b7
commit 6df8a513dc
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -520,13 +520,16 @@ is_file_compressed (const byte *buf, unsigned int buflen)
struct magic_compress_s
{
byte len;
byte extchk;
byte magic[5];
} magic[] =
{
{ 3, { 0x42, 0x5a, 0x68, 0x00 } }, /* bzip2 */
{ 3, { 0x1f, 0x8b, 0x08, 0x00 } }, /* gzip */
{ 4, { 0x50, 0x4b, 0x03, 0x04 } }, /* (pk)zip */
{ 5, { '%', 'P', 'D', 'F', '-'} } /* PDF */
{ 3, 0, { 0x42, 0x5a, 0x68, 0x00 } }, /* bzip2 */
{ 3, 0, { 0x1f, 0x8b, 0x08, 0x00 } }, /* gzip */
{ 4, 0, { 0x50, 0x4b, 0x03, 0x04 } }, /* (pk)zip */
{ 5, 0, { '%', 'P', 'D', 'F', '-'} }, /* PDF */
{ 4, 1, { 0xff, 0xd8, 0xff, 0xe0 } }, /* Maybe JFIF */
{ 5, 2, { 0x89, 'P','N','G', 0x0d} } /* Likely PNG */
};
if ( buflen < 6 )
@ -536,9 +539,24 @@ is_file_compressed (const byte *buf, unsigned int buflen)
for ( i = 0; i < DIM (magic); i++ )
{
if ( !memcmp( buf, magic[i].magic, magic[i].len ))
if (!memcmp( buf, magic[i].magic, magic[i].len))
{
return 1; /* Is compressed. */
switch (magic[i].extchk)
{
case 0:
return 1; /* Is compressed. */
case 1:
if (buflen > 11 && !memcmp (buf + 6, "JFIF", 5))
return 1; /* JFIF: this likely a compressed JPEG. */
break;
case 2:
if (buflen > 8
&& buf[5] == 0x0a && buf[6] == 0x1a && buf[7] == 0x0a)
return 1; /* This is a PNG. */
break;
default:
break;
}
}
}