mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
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.
This commit is contained in:
parent
8012622e1b
commit
99f206c055
2 changed files with 17 additions and 20 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
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>
|
2008-06-15 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
* gst/matroska/ebml-read.c:
|
* gst/matroska/ebml-read.c:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <gst/floatcast/floatcast.h>
|
||||||
|
|
||||||
#include "ebml-read.h"
|
#include "ebml-read.h"
|
||||||
#include "ebml-ids.h"
|
#include "ebml-ids.h"
|
||||||
|
@ -692,21 +693,24 @@ struct _ext_float
|
||||||
static gdouble
|
static gdouble
|
||||||
_ext2dbl (guint8 * data)
|
_ext2dbl (guint8 * data)
|
||||||
{
|
{
|
||||||
struct _ext_float *ext = (struct _ext_float *) data;
|
struct _ext_float ext;
|
||||||
|
|
||||||
guint64 m = 0;
|
guint64 m = 0;
|
||||||
|
|
||||||
gint e, i;
|
gint e, i;
|
||||||
|
|
||||||
|
memcpy (&ext.exponent, data, 2);
|
||||||
|
memcpy (&ext.mantissa, data + 2, 8);
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
m = (m << 8) + ext->mantissa[i];
|
m = (m << 8) + ext.mantissa[i];
|
||||||
e = (((gint) ext->exponent[0] & 0x7f) << 8) | ext->exponent[1];
|
e = (((gint) ext.exponent[0] & 0x7f) << 8) | ext.exponent[1];
|
||||||
if (e == 0x7fff && m)
|
if (e == 0x7fff && m)
|
||||||
return 0.0 / 0.0;
|
return 0.0 / 0.0;
|
||||||
e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
|
e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
|
||||||
* mantissa bit is written as opposed to the
|
* mantissa bit is written as opposed to the
|
||||||
* single and double precision formats */
|
* single and double precision formats */
|
||||||
if (ext->exponent[0] & 0x80)
|
if (ext.exponent[0] & 0x80)
|
||||||
m = -m;
|
m = -m;
|
||||||
return ldexp (m, e);
|
return ldexp (m, e);
|
||||||
}
|
}
|
||||||
|
@ -739,27 +743,15 @@ gst_ebml_read_float (GstEbmlRead * ebml, guint32 * id, gdouble * num)
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
gfloat f;
|
gfloat f;
|
||||||
|
|
||||||
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
memcpy (&f, data, 4);
|
||||||
f = *(gfloat *) data;
|
f = GFLOAT_FROM_BE (f);
|
||||||
#else
|
|
||||||
while (size > 0) {
|
|
||||||
((guint8 *) & f)[size - 1] = data[4 - size];
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*num = f;
|
*num = f;
|
||||||
} else if (size == 8) {
|
} else if (size == 8) {
|
||||||
gdouble d;
|
gdouble d;
|
||||||
|
|
||||||
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
memcpy (&d, data, 8);
|
||||||
d = *(gdouble *) data;
|
d = GDOUBLE_FROM_BE (d);
|
||||||
#else
|
|
||||||
while (size > 0) {
|
|
||||||
((guint8 *) & d)[size - 1] = data[8 - size];
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*num = d;
|
*num = d;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue