Commit 99f206c0 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

gst/matroska/ebml-read.c: Prevent unaligned memory access when reading floats.

Original commit message from CVS:
* gst/matroska/ebml-read.c: (_ext2dbl), (gst_ebml_read_float):
Prevent unaligned memory access when reading floats.
parent 8012622e
2008-06-15 Sebastian Dröge <slomo@circular-chaos.org>
* gst/matroska/ebml-read.c: (_ext2dbl), (gst_ebml_read_float):
Prevent unaligned memory access when reading floats.
2008-06-15 Sebastian Dröge <slomo@circular-chaos.org>
 
* gst/matroska/ebml-read.c:
......
......@@ -24,6 +24,7 @@
#endif
#include <string.h>
#include <gst/floatcast/floatcast.h>
#include "ebml-read.h"
#include "ebml-ids.h"
......@@ -692,21 +693,24 @@ struct _ext_float
static gdouble
_ext2dbl (guint8 * data)
{
struct _ext_float *ext = (struct _ext_float *) data;
struct _ext_float ext;
guint64 m = 0;
gint e, i;
memcpy (&ext.exponent, data, 2);
memcpy (&ext.mantissa, data + 2, 8);
for (i = 0; i < 8; i++)
m = (m << 8) + ext->mantissa[i];
e = (((gint) ext->exponent[0] & 0x7f) << 8) | ext->exponent[1];
m = (m << 8) + ext.mantissa[i];
e = (((gint) ext.exponent[0] & 0x7f) << 8) | ext.exponent[1];
if (e == 0x7fff && m)
return 0.0 / 0.0;
e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
* mantissa bit is written as opposed to the
* single and double precision formats */
if (ext->exponent[0] & 0x80)
if (ext.exponent[0] & 0x80)
m = -m;
return ldexp (m, e);
}
......@@ -739,27 +743,15 @@ gst_ebml_read_float (GstEbmlRead * ebml, guint32 * id, gdouble * num)
if (size == 4) {
gfloat f;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
f = *(gfloat *) data;
#else
while (size > 0) {
((guint8 *) & f)[size - 1] = data[4 - size];
size--;
}
#endif
memcpy (&f, data, 4);
f = GFLOAT_FROM_BE (f);
*num = f;
} else if (size == 8) {
gdouble d;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
d = *(gdouble *) data;
#else
while (size > 0) {
((guint8 *) & d)[size - 1] = data[8 - size];
size--;
}
#endif
memcpy (&d, data, 8);
d = GDOUBLE_FROM_BE (d);
*num = d;
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment