diff options
author | Dan Stoza <stoza@google.com> | 2015-04-30 21:57:15 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-30 21:57:15 +0000 |
commit | 676d10b2709059079823698cb6b16e71a97d6d8b (patch) | |
tree | cfd87a16e29828958bcd730346c1b093d044e078 /services/surfaceflinger | |
parent | ed6e907bc7a259d85c6a6c141a06a06e5c0b224c (diff) | |
parent | ab79e33ef3a21a2b14bf15bc4c85aef247b4ad95 (diff) | |
download | frameworks_native-676d10b2709059079823698cb6b16e71a97d6d8b.zip frameworks_native-676d10b2709059079823698cb6b16e71a97d6d8b.tar.gz frameworks_native-676d10b2709059079823698cb6b16e71a97d6d8b.tar.bz2 |
Merge "SurfaceFlinger: Fix integer overflow in Mesh ctor"
Diffstat (limited to 'services/surfaceflinger')
-rw-r--r-- | services/surfaceflinger/RenderEngine/Mesh.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/services/surfaceflinger/RenderEngine/Mesh.cpp b/services/surfaceflinger/RenderEngine/Mesh.cpp index 3f50cb0..ffd9be2 100644 --- a/services/surfaceflinger/RenderEngine/Mesh.cpp +++ b/services/surfaceflinger/RenderEngine/Mesh.cpp @@ -16,14 +16,40 @@ #include "Mesh.h" +#include <utils/Log.h> + namespace android { Mesh::Mesh(Primitive primitive, size_t vertexCount, size_t vertexSize, size_t texCoordSize) : mVertexCount(vertexCount), mVertexSize(vertexSize), mTexCoordsSize(texCoordSize), mPrimitive(primitive) { - mVertices = new float[(vertexSize + texCoordSize) * vertexCount]; - mStride = mVertexSize + mTexCoordsSize; + if (vertexCount == 0) { + mVertices = new float[1]; + mVertices[0] = 0.0f; + mStride = 0; + return; + } + + size_t stride = vertexSize + texCoordSize; + size_t remainder = (stride * vertexCount) / vertexCount; + // Since all of the input parameters are unsigned, if stride is less than + // either vertexSize or texCoordSize, it must have overflowed. remainder + // will be equal to stride as long as stride * vertexCount doesn't overflow. + if ((stride < vertexSize) || (remainder != stride)) { + ALOGE("Overflow in Mesh(..., %zu, %zu, %zu)", vertexCount, vertexSize, + texCoordSize); + mVertices = new float[1]; + mVertices[0] = 0.0f; + mVertexCount = 0; + mVertexSize = 0; + mTexCoordsSize = 0; + mStride = 0; + return; + } + + mVertices = new float[stride * vertexCount]; + mStride = stride; } Mesh::~Mesh() { |