Bug 504766. qcms: Fix unaligned reads in qcms. r=jrmuizel
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 08 Sep 2009 11:36:28 -0400
changeset 32308 e8207773d54d79439940ed836f54027d7ed4dab1
parent 32307 4697642cc718413a3decf033cbf1d5b3a6e2e4bb
child 32309 69f32850f63505f9f3bb57d9d348fc683f32fc7e
push id8979
push userjmuizelaar@mozilla.com
push dateTue, 08 Sep 2009 15:38:44 +0000
treeherdermozilla-central@e8207773d54d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs504766
milestone1.9.3a1pre
Bug 504766. qcms: Fix unaligned reads in qcms. r=jrmuizel Offsets are not guaranteed to be aligned, so don't assume that they are. memcpy instead of just casting and dereferencing.
gfx/qcms/iccread.c
--- a/gfx/qcms/iccread.c
+++ b/gfx/qcms/iccread.c
@@ -82,27 +82,31 @@ static uint32_t read_u32(struct mem_sour
 {
 	/* Subtract from mem->size instead of the more intuitive adding to offset.
 	 * This avoids overflowing offset. The subtraction is safe because
 	 * mem->size is guaranteed to be > 4 */
 	if (offset > mem->size - 4) {
 		invalid_source(mem, "Invalid offset");
 		return 0;
 	} else {
-		return be32_to_cpu(*(__be32*)(mem->buf + offset));
+		__be32 k;
+		memcpy(&k, mem->buf + offset, sizeof(__be32));
+		return be32_to_cpu(k);
 	}
 }
 
 static uint16_t read_u16(struct mem_source *mem, size_t offset)
 {
 	if (offset > mem->size - 2) {
 		invalid_source(mem, "Invalid offset");
 		return 0;
 	} else {
-		return be16_to_cpu(*(__be16*)(mem->buf + offset));
+		__be16 k;
+		memcpy(&k, mem->buf + offset, sizeof(__be16));
+		return be16_to_cpu(k);
 	}
 }
 
 static uint8_t read_u8(struct mem_source *mem, size_t offset)
 {
 	if (offset > mem->size - 1) {
 		invalid_source(mem, "Invalid offset");
 		return 0;