am ebebf9c3: Merge change 24618 into eclair

Merge commit 'ebebf9c36c0112d99cb2e11953febdff8ba5ff23' into eclair-plus-aosp

* commit 'ebebf9c36c0112d99cb2e11953febdff8ba5ff23':
  AGL's glCompressedTexImage2D now checks the imageSize parameter.
This commit is contained in:
Jack Palevich
2009-09-10 17:51:50 -07:00
committed by Android Git Automerger

View File

@@ -409,6 +409,49 @@ int createTextureSurface(ogles_context_t* c,
return 0; return 0;
} }
static size_t dataSizePalette4(int numLevels, int width, int height, int format)
{
int indexBits = 8;
int entrySize = 0;
switch (format) {
case GL_PALETTE4_RGB8_OES:
indexBits = 4;
/* FALLTHROUGH */
case GL_PALETTE8_RGB8_OES:
entrySize = 3;
break;
case GL_PALETTE4_RGBA8_OES:
indexBits = 4;
/* FALLTHROUGH */
case GL_PALETTE8_RGBA8_OES:
entrySize = 4;
break;
case GL_PALETTE4_R5_G6_B5_OES:
case GL_PALETTE4_RGBA4_OES:
case GL_PALETTE4_RGB5_A1_OES:
indexBits = 4;
/* FALLTHROUGH */
case GL_PALETTE8_R5_G6_B5_OES:
case GL_PALETTE8_RGBA4_OES:
case GL_PALETTE8_RGB5_A1_OES:
entrySize = 2;
break;
}
size_t size = (1 << indexBits) * entrySize; // palette size
for (int i=0 ; i< numLevels ; i++) {
int w = (width >> i) ? : 1;
int h = (height >> i) ? : 1;
int levelSize = h * ((w * indexBits) / 8) ? : 1;
size += levelSize;
}
return size;
}
static void decodePalette4(const GLvoid *data, int level, int width, int height, static void decodePalette4(const GLvoid *data, int level, int width, int height,
void *surface, int stride, int format) void *surface, int stride, int format)
@@ -443,6 +486,7 @@ static void decodePalette4(const GLvoid *data, int level, int width, int height,
} }
const int paletteSize = (1 << indexBits) * entrySize; const int paletteSize = (1 << indexBits) * entrySize;
uint8_t const* pixels = (uint8_t *)data + paletteSize; uint8_t const* pixels = (uint8_t *)data + paletteSize;
for (int i=0 ; i<level ; i++) { for (int i=0 ; i<level ; i++) {
int w = (width >> i) ? : 1; int w = (width >> i) ? : 1;
@@ -1091,6 +1135,12 @@ void glCompressedTexImage2D(
GGLSurface* surface; GGLSurface* surface;
// all mipmap levels are specified at once. // all mipmap levels are specified at once.
const int numLevels = level<0 ? -level : 1; const int numLevels = level<0 ? -level : 1;
if (dataSizePalette4(numLevels, width, height, format) > imageSize) {
ogles_error(c, GL_INVALID_VALUE);
return;
}
for (int i=0 ; i<numLevels ; i++) { for (int i=0 ; i<numLevels ; i++) {
int lod_w = (width >> i) ? : 1; int lod_w = (width >> i) ? : 1;
int lod_h = (height >> i) ? : 1; int lod_h = (height >> i) ? : 1;