mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-28 12:41:25 +08:00
[c] Fix weighted vertex buffer overflow using realloc growth
This commit is contained in:
parent
4572db6554
commit
c9cd6428dc
@ -1027,13 +1027,33 @@ static int _readVertices(_dataInput *input, float **vertices, int *verticesLengt
|
|||||||
return *verticesLength;
|
return *verticesLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *v = MALLOC(float, (*verticesLength) * 3 * 3);
|
int vertexCapacity = (*verticesLength) * 3 * 3;
|
||||||
int *b = MALLOC(int, (*verticesLength) * 3);
|
int boneCapacity = (*verticesLength) * 3;
|
||||||
|
if (vertexCapacity < 8) vertexCapacity = 8;
|
||||||
|
if (boneCapacity < 8) boneCapacity = 8;
|
||||||
|
float *v = MALLOC(float, vertexCapacity);
|
||||||
|
int *b = MALLOC(int, boneCapacity);
|
||||||
int boneIdx = 0;
|
int boneIdx = 0;
|
||||||
int vertexIdx = 0;
|
int vertexIdx = 0;
|
||||||
for (int i = 0; i < vertexCount; ++i) {
|
for (int i = 0; i < vertexCount; ++i) {
|
||||||
int boneCount = readVarint(input, 1);
|
int boneCount = readVarint(input, 1);
|
||||||
|
int requiredBones = boneIdx + 1 + boneCount;
|
||||||
|
if (requiredBones > boneCapacity) {
|
||||||
|
while (boneCapacity < requiredBones) {
|
||||||
|
boneCapacity += boneCapacity >> 1;
|
||||||
|
}
|
||||||
|
b = REALLOC(b, int, boneCapacity);
|
||||||
|
}
|
||||||
b[boneIdx++] = boneCount;
|
b[boneIdx++] = boneCount;
|
||||||
|
|
||||||
|
int requiredVertices = vertexIdx + boneCount * 3;
|
||||||
|
if (requiredVertices > vertexCapacity) {
|
||||||
|
while (vertexCapacity < requiredVertices) {
|
||||||
|
vertexCapacity += vertexCapacity >> 1;
|
||||||
|
}
|
||||||
|
v = REALLOC(v, float, vertexCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < boneCount; ++ii) {
|
for (int ii = 0; ii < boneCount; ++ii) {
|
||||||
b[boneIdx++] = readVarint(input, 1);
|
b[boneIdx++] = readVarint(input, 1);
|
||||||
v[vertexIdx++] = readFloat(input) * scale;
|
v[vertexIdx++] = readFloat(input) * scale;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user