Browse Source

[Fix] Properly detect encrypted files in zip archives

tags/1.9.2
Vsevolod Stakhov 5 years ago
parent
commit
6861c93af2
2 changed files with 29 additions and 2 deletions
  1. 27
    0
      src/libmime/archives.c
  2. 2
    2
      src/libmime/archives.h

+ 27
- 0
src/libmime/archives.c View File

arch); arch);


while (cd < eocd) { while (cd < eocd) {
guint16 flags;

/* Read central directory record */ /* Read central directory record */
if (eocd - cd < cd_basic_len || if (eocd - cd < cd_basic_len ||
memcmp (cd, cd_magic, sizeof (cd_magic)) != 0) { memcmp (cd, cd_magic, sizeof (cd_magic)) != 0) {
return; return;
} }


memcpy (&flags, cd + 8, sizeof (guint16));
flags = GUINT16_FROM_LE (flags);
memcpy (&comp_size, cd + 20, sizeof (guint32)); memcpy (&comp_size, cd + 20, sizeof (guint32));
comp_size = GUINT32_FROM_LE (comp_size); comp_size = GUINT32_FROM_LE (comp_size);
memcpy (&uncomp_size, cd + 24, sizeof (guint32)); memcpy (&uncomp_size, cd + 24, sizeof (guint32));
f->compressed_size = comp_size; f->compressed_size = comp_size;
f->uncompressed_size = uncomp_size; f->uncompressed_size = uncomp_size;


if (flags & 0x41u) {
f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED;
}

if (f->fname) { if (f->fname) {
g_ptr_array_add (arch->files, f); g_ptr_array_add (arch->files, f);
msg_debug_archive ("found file in zip archive: %v", f->fname); msg_debug_archive ("found file in zip archive: %v", f->fname);
g_free (f); g_free (f);
} }


/* Process extra fields */
const guchar *extra = cd + fname_len + cd_basic_len;
p = extra;

while (p + sizeof (guint16) * 2 < extra + extra_len) {
guint16 hid, hlen;

memcpy (&hid, p, sizeof (guint16));
hid = GUINT16_FROM_LE (hid);
memcpy (&hlen, p + sizeof (guint16), sizeof (guint16));
hlen = GUINT16_FROM_LE (hlen);

if (hid == 0x0017) {
f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED;
}

p += hlen + sizeof (guint16) * 2;
}

cd += fname_len + comment_len + extra_len + cd_basic_len; cd += fname_len + comment_len + extra_len + cd_basic_len;
} }



+ 2
- 2
src/libmime/archives.h View File

}; };


enum rspamd_archive_flags { enum rspamd_archive_flags {
RSPAMD_ARCHIVE_ENCRYPTED = (1 << 0),
RSPAMD_ARCHIVE_ENCRYPTED = (1u << 0u),
}; };


enum rspamd_archive_file_flags { enum rspamd_archive_file_flags {
RSPAMD_ARCHIVE_FILE_ENCRYPTED = (1 << 0),
RSPAMD_ARCHIVE_FILE_ENCRYPTED = (1u << 0u),
}; };


struct rspamd_archive_file { struct rspamd_archive_file {

Loading…
Cancel
Save