aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wiretap/mpeg.c17
-rw-r--r--wsutil/mpeg-audio.c27
-rw-r--r--wsutil/mpeg-audio.h3
3 files changed, 46 insertions, 1 deletions
diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c
index fc60e66419..ea81f8ffba 100644
--- a/wiretap/mpeg.c
+++ b/wiretap/mpeg.c
@@ -163,7 +163,22 @@ mpeg_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf,
}
}
} else {
- packet_size = mpeg_resync(fh, err);
+ if ((n & 0xffffff00) == 0x49443300) {
+ /* We have an ID3v2 header; read the size */
+ if (file_seek(fh, 6, SEEK_CUR, err) == -1)
+ return FALSE;
+ if (!wtap_read_bytes_or_eof(fh, &n, sizeof n, err, err_info))
+ return FALSE;
+ if (file_seek(fh, -(gint64)(6+sizeof(n)), SEEK_CUR, err) == -1)
+ return FALSE;
+ n = g_ntohl(n);
+
+ /* ID3v2 size does not include the 10-byte header */
+ packet_size = decode_synchsafe_int(n) + 10;
+ } else {
+ packet_size = mpeg_resync(fh, err);
+ }
+
if (packet_size == 0)
return FALSE;
}
diff --git a/wsutil/mpeg-audio.c b/wsutil/mpeg-audio.c
index 00ac78d8bd..e22bef38c8 100644
--- a/wsutil/mpeg-audio.c
+++ b/wsutil/mpeg-audio.c
@@ -81,6 +81,33 @@ mpa_padding(const struct mpa *mpa)
return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
}
+/* Decode an ID3v2 synchsafe integer.
+ * See https://id3.org/id3v2.4.0-structure section 6.2.
+ */
+guint32
+decode_synchsafe_int(guint32 input)
+{
+ guint32 value;
+
+ /* High-order byte */
+ value = (input >> 24) & 0x7f;
+ /* Shift the result left to make room for the next 7 bits */
+ value <<= 7;
+
+ /* Now OR in the 2nd byte */
+ value |= (input >> 16) & 0x7f;
+ value <<= 7;
+
+ /* ... and the 3rd */
+ value |= (input >> 8) & 0x7f;
+ value <<= 7;
+
+ /* For the 4th byte don't do the shift */
+ value |= input & 0x7f;
+
+ return value;
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/wsutil/mpeg-audio.h b/wsutil/mpeg-audio.h
index ced51ff745..e496a9b10d 100644
--- a/wsutil/mpeg-audio.h
+++ b/wsutil/mpeg-audio.h
@@ -11,6 +11,7 @@
#ifndef MPA_H
#define MPA_H 1
+#include <glib.h>
#include "ws_symbol_export.h"
struct mpa {
@@ -71,6 +72,8 @@ WS_DLL_PUBLIC
unsigned int mpa_frequency(const struct mpa *);
WS_DLL_PUBLIC
unsigned int mpa_padding(const struct mpa *);
+WS_DLL_PUBLIC
+guint32 decode_synchsafe_int(guint32);
#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
/ mpa_frequency(mpa) / 8)