~ubuntu-branches/ubuntu/oneiric/clamav/oneiric-updates

« back to all changes in this revision

Viewing changes to libclamav/pdf.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Seth Arnold, Scott Kitterman
  • Date: 2013-04-25 23:41:55 UTC
  • mfrom: (114.1.2 oneiric-security)
  • Revision ID: package-import@ubuntu.com-20130425234155-5e19oj23w5sm7n4v
Tags: 0.97.8+dfsg-1ubuntu1.11.10.1
[ Seth Arnold ]
* SECURITY UPDATE: Updated to 0.97.8 to fix multiple security issues.
  - CVE-2013-2020 and CVE-2013-2021

[ Scott Kitterman ]
* Merge from Debian unstable (LP: #1172981).  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
        case MANY_FILTERS:
297
297
            s = "more than 2 filters per obj";
298
298
            break;
 
299
        case DECRYPTABLE_PDF:
 
300
            s = "decryptable PDF";
 
301
            break;
299
302
    }
300
303
    cli_dbgmsg("cli_pdf: %s flagged in object %u %u\n", s, obj->id>>8, obj->id&0xff);
301
304
}
567
570
    char *ascii_decoded = NULL;
568
571
    int dump = 1;
569
572
 
 
573
    cli_dbgmsg("pdf_extract_obj: obj %u %u\n", obj->id>>8, obj->id&0xff);
 
574
 
570
575
    /* TODO: call bytecode hook here, allow override dumpability */
571
576
    if ((!(obj->flags & (1 << OBJ_STREAM)) ||
572
577
        (obj->flags & (1 << OBJ_HASFILTERS)))
585
590
    }
586
591
    if (!dump)
587
592
        return CL_CLEAN;
588
 
    cli_dbgmsg("cli_pdf: dumping obj %u %u\n", obj->id>>8, obj->id);
 
593
    cli_dbgmsg("cli_pdf: dumping obj %u %u\n", obj->id>>8, obj->id&0xff);
589
594
    snprintf(fullname, sizeof(fullname), "%s"PATHSEP"pdf%02u", pdf->dir, pdf->files++);
590
595
    fout = open(fullname,O_RDWR|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
591
596
    if (fout < 0) {
907
912
        q2 = pdf_nextobject(q, bytesleft);
908
913
        bytesleft -= q2 -q;
909
914
        if (!q2 || bytesleft < 0) {
 
915
            cli_dbgmsg("cli_pdf: %u %u obj: no dictionary\n", obj->id>>8, obj->id&0xff);
910
916
            return;
911
917
        }
912
918
        q3 = memchr(q-1, '<', q2-q+1);
922
928
        q2 = pdf_nextobject(q, bytesleft);
923
929
        bytesleft -= q2 -q;
924
930
        if (!q2 || bytesleft < 0) {
 
931
            cli_dbgmsg("cli_pdf: %u %u obj: broken dictionary\n", obj->id>>8, obj->id&0xff);
925
932
            return;
926
933
        }
927
934
        q3 = memchr(q-1, '>', q2-q+1);
1262
1269
            password_empty = 1;
1263
1270
            /* Algorithm 3.2a could be used to recover encryption key */
1264
1271
        }
1265
 
    } else {
 
1272
    } else if ((R >= 2) && (R <= 4)) {
1266
1273
        /* 7.6.3.3 Algorithm 2 */
1267
1274
        cli_md5_init(&md5);
1268
1275
        /* empty password, password == padding */
1276
1283
            cli_md5_update(&md5, &v, 4);
1277
1284
        }
1278
1285
        cli_md5_final(result, &md5);
 
1286
        if (length > 128)
 
1287
            length = 128;
1279
1288
        if (R >= 3) {
1280
 
            if (length > 128)
1281
 
                length = 128;
1282
1289
            for (i=0;i<50;i++) {
1283
1290
                cli_md5_init(&md5);
1284
1291
                cli_md5_update(&md5, result, length/8);
1329
1336
            cli_dbgmsg("cli_pdf: invalid revision %d\n", R);
1330
1337
        }
1331
1338
    }
 
1339
    else {
 
1340
        /* Supported R is in {2,3,4,5} */
 
1341
        cli_dbgmsg("cli_pdf: R value out of range\n");
 
1342
        return;
 
1343
    }
1332
1344
    if (password_empty) {
1333
1345
        cli_dbgmsg("cli_pdf: user password is empty\n");
1334
1346
        /* The key we computed above is the key used to encrypt the streams.
1395
1407
            cli_dbgmsg("cli_pdf: invalid R\n");
1396
1408
            break;
1397
1409
        }
 
1410
        if ((R > 5) || (R < 2)) {
 
1411
            cli_dbgmsg("cli_pdf: R value outside supported range [2..5]\n");
 
1412
            break;
 
1413
        }
1398
1414
 
1399
1415
        if (R < 5)
1400
1416
            oulen = 32;