BLF: Properly skip 0-length containers
authorGiovanni Musto <giovanni.musto@partner.italdesign.it>
Wed, 10 Apr 2024 14:28:27 +0000 (16:28 +0200)
committerAlexis La Goutte <alexis.lagoutte@gmail.com>
Wed, 10 Apr 2024 18:59:47 +0000 (18:59 +0000)
wiretap/blf.c

index da0f44d7b54fd34ba76db75cd568216af0298d41..883195b06e33c6f6e2b323c63b61536060ca48c6 100644 (file)
@@ -661,11 +661,6 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, blf_log_container_t *con
         return true;
     }
 
-    if (container->real_length == 0) {
-        ws_info("blf_pull_logcontainer_into_memory: found container with 0 length");
-        return true;
-    }
-
     /* pull compressed data into buffer */
     if (container->infile_start_pos < 0) {
         /*
@@ -711,6 +706,26 @@ blf_pull_logcontainer_into_memory(blf_params_t *params, blf_log_container_t *con
         return false;
     }
 
+    if (container->real_length == 0) {
+        ws_info("blf_pull_logcontainer_into_memory: found container with 0 length");
+        /* Skip empty container */
+        if (!wtap_read_bytes_or_eof(params->fh, NULL, (unsigned int)data_length, err, err_info)) {
+            if (*err == WTAP_ERR_SHORT_READ) {
+                /*
+                 * XXX - our caller will turn this into an EOF.
+                 * How *should* it be treated?
+                 * For now, we turn it into Yet Another Internal Error,
+                 * pending having better documentation of the file
+                 * format.
+                 */
+                *err = WTAP_ERR_INTERNAL;
+                *err_info = ws_strdup("blf_pull_logcontainer_into_memory: short read on 0-length container");
+            }
+            return false;
+        }
+        return true;
+    }
+
     if (container->compression_method == BLF_COMPRESSION_NONE) {
         unsigned char* buf = g_try_malloc0((size_t)container->real_length);
         if (buf == NULL) {