summaryrefslogtreecommitdiff
path: root/dist/Mesa
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2008-08-12 23:16:08 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2008-08-12 23:16:08 +0000
commit9c543524725529b75577581688ef3d23abc0c13e (patch)
tree4fcd3f4053020c3a3130ce3885d55041bba15a13 /dist/Mesa
parent912b9785e1400bcbdafee6d91282b71fec2c2ccc (diff)
Fix out-of-bounds memory access in swizzle_copy(). My fix was different,
but this one (from mesa, prompted by my diff) should run a little faster. Now mplayer -vo gl or gl2 works with dri enabled. Detected by otto malloc. Some debugging help from todd. ok matthieu@, todd@.
Diffstat (limited to 'dist/Mesa')
-rw-r--r--dist/Mesa/src/mesa/main/texstore.c120
1 files changed, 90 insertions, 30 deletions
diff --git a/dist/Mesa/src/mesa/main/texstore.c b/dist/Mesa/src/mesa/main/texstore.c
index 2ac458b45..92aab75ab 100644
--- a/dist/Mesa/src/mesa/main/texstore.c
+++ b/dist/Mesa/src/mesa/main/texstore.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.1
+ * Version: 7.1
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -661,56 +661,116 @@ static void
swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,
GLuint srcComponents, const GLubyte *map, GLuint count)
{
+#define SWZ_CPY(dst, src, count, dstComps, srcComps) \
+ do { \
+ GLuint i; \
+ for (i = 0; i < count; i++) { \
+ GLuint j; \
+ if (srcComps == 4) { \
+ COPY_4UBV(tmp, src); \
+ } \
+ else { \
+ for (j = 0; j < srcComps; j++) { \
+ tmp[j] = src[j]; \
+ } \
+ } \
+ src += srcComps; \
+ for (j = 0; j < dstComps; j++) { \
+ dst[j] = tmp[map[j]]; \
+ } \
+ dst += dstComps; \
+ } \
+ } while (0)
+
GLubyte tmp[6];
- GLuint i;
tmp[ZERO] = 0x0;
tmp[ONE] = 0xff;
+ ASSERT(srcComponents <= 4);
+ ASSERT(dstComponents <= 4);
+
switch (dstComponents) {
case 4:
- for (i = 0; i < count; i++) {
- COPY_4UBV(tmp, src);
- src += srcComponents;
- dst[0] = tmp[map[0]];
- dst[1] = tmp[map[1]];
- dst[2] = tmp[map[2]];
- dst[3] = tmp[map[3]];
- dst += 4;
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 4, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 4, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 4, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 4, 1);
+ break;
+ default:
+ ;
}
break;
case 3:
- for (i = 0; i < count; i++) {
- COPY_4UBV(tmp, src);
- src += srcComponents;
- dst[0] = tmp[map[0]];
- dst[1] = tmp[map[1]];
- dst[2] = tmp[map[2]];
- dst += 3;
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 3, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 3, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 3, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 3, 1);
+ break;
+ default:
+ ;
}
break;
case 2:
- for (i = 0; i < count; i++) {
- COPY_4UBV(tmp, src);
- src += srcComponents;
- dst[0] = tmp[map[0]];
- dst[1] = tmp[map[1]];
- dst += 2;
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 2, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 2, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 2, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 2, 1);
+ break;
+ default:
+ ;
}
break;
case 1:
- /* XXX investigate valgrind invalid read when running demos/texenv.c */
- for (i = 0; i < count; i++) {
- COPY_4UBV(tmp, src);
- src += srcComponents;
- dst[0] = tmp[map[0]];
- dst += 1;
+ switch (srcComponents) {
+ case 4:
+ SWZ_CPY(dst, src, count, 1, 4);
+ break;
+ case 3:
+ SWZ_CPY(dst, src, count, 1, 3);
+ break;
+ case 2:
+ SWZ_CPY(dst, src, count, 1, 2);
+ break;
+ case 1:
+ SWZ_CPY(dst, src, count, 1, 1);
+ break;
+ default:
+ ;
}
break;
+ default:
+ ;
}
+#undef SWZ_CPY
}
+
static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };
static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };