Commits

Anonymous committed 8b467f6

Fix more errors found by fuzzing

  • Participants
  • Parent commits 52efc25

Comments (0)

Files changed (4)

hachoir-metadata/hachoir_metadata/audio.py

         self.compression = audio["codec"].display
         if "info" in audio:
             self.comment = audio["info"].value
-        bits_per_sample = audio.getBitsPerSample()
-        if bits_per_sample:
-            self.bits_per_sample = bits_per_sample
-            self.bit_rate = bits_per_sample * self.nb_channel[0] * self.sample_rate[0]
-            if self.bit_rate[0]:
-                self.duration = audio["audio_data"].size * 1000 / self.bit_rate[0]
+        self.bits_per_sample = audio.getBitsPerSample()
+        if hasattr(self, "bits_per_sample"):
+            self.bit_rate = self.bits_per_sample[0] * audio["channels"].value * audio["sample_rate"].value
+        if "audio_data" in audio \
+        and hasattr(self, "bit_rate"):
+            self.duration = audio["audio_data"].size * 1000 / self.bit_rate[0]
 
 class RealAudioMetadata(Metadata):
     def extract(self, real):

hachoir-metadata/hachoir_metadata/image.py

     XcfFile, TargaFile, WMF_File, PsdFile)
 from hachoir_parser.image.xcf import XcfProperty
 from hachoir_core.i18n import _
+from hachoir_core.error import HACHOIR_ERRORS
 
 class BmpMetadata(Metadata):
     def extract(self, image):
         self.bits_per_pixel = bpp
         self.compression = header["compression"].display
         if "time" in png:
-            self.creation_date = str(png["time"].value)
+            try:
+                self.creation_date = png["time"].value
+            except HACHOIR_ERRORS:
+                pass
         for comment in png.array("text"):
             if "text" not in comment:
                 continue

hachoir-metadata/hachoir_metadata/jpeg.py

     QUALITY_HASH_GRAY, QUALITY_SUM_GRAY)
 from hachoir_core.field import MissingField
 from hachoir_core.i18n import _
-from hachoir_core.error import warning
+from hachoir_core.error import warning, HACHOIR_ERRORS
 import types
 
 class JpegMetadata(Metadata):
         if "exif/content" in jpeg:
             for ifd in jpeg.array("exif/content/ifd"):
                 for entry in ifd.array("entry"):
-                    self.processIfdEntry(ifd, entry)
+                    try:
+                        self.processIfdEntry(ifd, entry)
+                    except HACHOIR_ERRORS:
+                        pass
         if "psd/content" in jpeg:
             psd = jpeg["psd/content"]
             if "iptc" in psd:
         elif tag == ExifEntry.TAG_EXPOSURE:
             if not value:
                 return
-            value = "1/%g" % (1/value)
+            if isinstance(value, float):
+                value = "1/%g" % (1/value)
         elif rational:
             value = "%.3g" % value
 

hachoir-metadata/hachoir_metadata/riff.py

         self.sample_rate = format["sample_per_sec"].value
 
         self.compression = format["codec"].display
-        if "nb_sample/nb_sample" in wav:
-            self.duration = wav["nb_sample/nb_sample"].value * 1000 // self.sample_rate[0]
+        if "nb_sample/nb_sample" in wav \
+        and 0 < format["sample_per_sec"].value:
+            self.duration = wav["nb_sample/nb_sample"].value * 1000 // format["sample_per_sec"].value
         if format["codec"].value in (AUDIO_MICROSOFT_PCM, AUDIO_IEEE_FLOAT32):
             # Codec with fixed bit rate
-            self.bit_rate = self.nb_channel[0] * self.bits_per_sample[0] * self.sample_rate[0]
-            if not hasattr(self, "duration"):
+            self.bit_rate = format["nb_channel"].value * format["bit_per_sample"].value * format["sample_per_sec"].value
+            if not hasattr(self, "duration") \
+            and "audio_data/size" in wav \
+            and hasattr(self, "bit_rate"):
                 self.duration = wav["audio_data/size"].value * 8 * 1000 // self.bit_rate[0]
 
     def extract(self, riff):