Browse code

Use the new timeout facility

Shawn Webb authored on 2014/07/01 03:35:42
Showing 1 changed files
... ...
@@ -2513,6 +2513,18 @@ int cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
2513 2513
     /* must parse after finding all objs, so we can flag indirect objects */
2514 2514
     for (i=0;i<pdf.nobjs;i++) {
2515 2515
         struct pdf_obj *obj = &pdf.objs[i];
2516
+
2517
+        if (cli_checktimelimit(ctx) != CL_SUCCESS) {
2518
+            cli_errmsg("Timeout reached in the PDF parser\n");
2519
+            pdf_export_json(&pdf);
2520
+            free(pdf.objs);
2521
+            if (pdf.fileID)
2522
+                free(pdf.fileID);
2523
+            if (pdf.key)
2524
+                free(pdf.key);
2525
+            return CL_ETIMEOUT;
2526
+        }
2527
+
2516 2528
         pdf_parseobj(&pdf, obj);
2517 2529
     }
2518 2530
 
... ...
@@ -2548,6 +2560,18 @@ int cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
2548 2548
     /* extract PDF objs */
2549 2549
     for (i=0;!rc && i<pdf.nobjs;i++) {
2550 2550
         struct pdf_obj *obj = &pdf.objs[i];
2551
+
2552
+        if (cli_checktimelimit(ctx) != CL_SUCCESS) {
2553
+            cli_errmsg("Timeout reached in the PDF parser\n");
2554
+            pdf_export_json(&pdf);
2555
+            free(pdf.objs);
2556
+            if (pdf.fileID)
2557
+                free(pdf.fileID);
2558
+            if (pdf.key)
2559
+                free(pdf.key);
2560
+            return CL_ETIMEOUT;
2561
+        }
2562
+
2551 2563
         rc = pdf_extract_obj(&pdf, obj, PDF_EXTRACT_OBJ_SCAN);
2552 2564
         switch (rc) {
2553 2565
             case CL_EFORMAT: