Bug 629057. Backport the fix for bug 504766 (fixing unaligned reads) to 1.9.1. r=jmuizelaar, a1.9.1.20=dveditz default tip
authorLandry Breuil <landry@openbsd.org>
Tue, 05 Jul 2011 17:22:13 -0400
changeset 27427 920bcf17a9e120114a7b8989ad9be08aa2630909
parent 27426 0efb6d76d4192e2bd657780dea0facaaf98d6cad
push id2732
push userdbaron@mozilla.com
push dateTue, 05 Jul 2011 21:29:35 +0000
reviewersjmuizelaar
bugs629057, 504766
milestone1.9.1.20pre
Bug 629057. Backport the fix for bug 504766 (fixing unaligned reads) to 1.9.1. r=jmuizelaar, a1.9.1.20=dveditz
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;