[vlc-commits] [Git][videolan/vlc][master] 3 commits: demux: image: fix jpeg probe size return check

François Cartegnie (@fcartegnie) gitlab at videolan.org
Tue Dec 20 14:22:18 UTC 2022



François Cartegnie pushed to branch master at VideoLAN / VLC


Commits:
a0e6c175 by Francois Cartegnie at 2022-12-20T14:08:35+00:00
demux: image: fix jpeg probe size return check

valid jpeg data offset being greater than 0xff

- - - - -
8b310b2f by Francois Cartegnie at 2022-12-20T14:08:35+00:00
demux: image: use proper type for peek

- - - - -
1c6749b8 by Francois Cartegnie at 2022-12-20T14:08:35+00:00
demux: image: fix probing jpeg starting with XMP

- - - - -


1 changed file:

- modules/demux/image.c


Changes:

=====================================
modules/demux/image.c
=====================================
@@ -393,9 +393,9 @@ static bool IsPnm(stream_t *s)
     return true;
 }
 
-static uint8_t FindJpegMarker(int *position, const uint8_t *data, int size)
+static uint8_t FindJpegMarker(size_t *position, const uint8_t *data, size_t size)
 {
-    for (int i = *position; i + 1 < size; i++) {
+    for (size_t i = *position; i + 1 < size; i++) {
         if (data[i + 0] != 0xff || data[i + 1] == 0x00)
             return 0xff;
         if (data[i + 1] != 0xff) {
@@ -408,8 +408,11 @@ static uint8_t FindJpegMarker(int *position, const uint8_t *data, int size)
 static bool IsJfif(stream_t *s)
 {
     const uint8_t *header;
-    int size = vlc_stream_Peek(s, &header, 256);
-    int position = 0;
+    ssize_t peek = vlc_stream_Peek(s, &header, 256);
+    if(peek < 256)
+        return false;
+    size_t size = (size_t) peek;
+    size_t position = 0;
 
     if (FindJpegMarker(&position, header, size) != 0xd8)
         return false;
@@ -450,24 +453,29 @@ static bool IsSpiff(stream_t *s)
     return true;
 }
 
-static bool IsExif(stream_t *s)
+#define EXIF_STRING "Exif" /* includes \0 */
+#define EXIF_XMP_STRING "http://ns.adobe.com/xap/1.0/" /* includes \0 */
+static bool IsExifXMP(stream_t *s)
 {
     const uint8_t *header;
-    ssize_t size = vlc_stream_Peek(s, &header, 256);
-    if (size == -1)
+    ssize_t peek = vlc_stream_Peek(s, &header, 256);
+    if (peek < 256)
         return false;
-    int position = 0;
+    size_t size = (size_t) peek;
+    size_t position = 0;
 
     if (FindJpegMarker(&position, header, size) != 0xd8)
         return false;
     if (FindJpegMarker(&position, header, size) != 0xe1)
         return false;
     position += 2;  /* Skip size */
-    if (position + 5 > size)
-        return false;
-    if (memcmp(&header[position], "Exif\0", 5))
-        return false;
-    return true;
+    if (position + sizeof(EXIF_STRING) <= size &&
+        !memcmp(&header[position], EXIF_STRING, sizeof(EXIF_STRING)))
+        return true;
+    if (position + sizeof(EXIF_XMP_STRING) <= size &&
+        !memcmp(&header[position], EXIF_XMP_STRING, sizeof(EXIF_XMP_STRING)))
+        return true;
+    return false;
 }
 
 static bool FindSVGmarker(int *position, const uint8_t *data, const int size, const char *marker)
@@ -636,7 +644,7 @@ static const image_format_t formats[] = {
       .detect = IsSpiff,
     },
     { .codec = VLC_CODEC_JPEG,
-      .detect = IsExif,
+      .detect = IsExifXMP,
     },
     { .codec = VLC_CODEC_WEBP,
       .detect = IsWebP,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b9d4730aa2c7c1938abca7be8d2f429973b49fe7...1c6749b8090a659678ff1cdbd80358405efac3f3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b9d4730aa2c7c1938abca7be8d2f429973b49fe7...1c6749b8090a659678ff1cdbd80358405efac3f3
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list