Skip to content

Commit 855eadf

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "Fix potential bug with reordered size/offset arguments."
2 parents 6972659 + 4cbe25a commit 855eadf

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

graphics/jni/android_renderscript_RenderScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011 The Android Open Source Project
2+
* Copyright (C) 2011-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -567,7 +567,7 @@ nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc,
567567
jint len = _env->GetArrayLength(data);
568568
LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
569569
jbyte *ptr = _env->GetByteArrayElements(data, NULL);
570-
rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes);
570+
rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
571571
_env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
572572
}
573573

libs/rs/rs.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Allocation1DElementData {
162162
param uint32_t x
163163
param uint32_t lod
164164
param const void *data
165-
param uint32_t comp_offset
165+
param size_t comp_offset
166166
}
167167

168168
Allocation2DData {
@@ -183,7 +183,7 @@ Allocation2DElementData {
183183
param uint32_t lod
184184
param RsAllocationCubemapFace face
185185
param const void *data
186-
param uint32_t element_offset
186+
param size_t element_offset
187187
}
188188

189189
AllocationGenerateMipmaps {

libs/rs/rsAllocation.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,11 +71,11 @@ void Allocation::read(void *data) {
7171
}
7272

7373
void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
74-
uint32_t count, const void *data, uint32_t sizeBytes) {
75-
const uint32_t eSize = mHal.state.type->getElementSizeBytes();
74+
uint32_t count, const void *data, size_t sizeBytes) {
75+
const size_t eSize = mHal.state.type->getElementSizeBytes();
7676

7777
if ((count * eSize) != sizeBytes) {
78-
ALOGE("Allocation::subData called with mismatched size expected %i, got %i",
78+
ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
7979
(count * eSize), sizeBytes);
8080
mHal.state.type->dumpLOGV("type info");
8181
return;
@@ -86,14 +86,14 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
8686
}
8787

8888
void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
89-
uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) {
90-
const uint32_t eSize = mHal.state.elementSizeBytes;
91-
const uint32_t lineSize = eSize * w;
89+
uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
90+
const size_t eSize = mHal.state.elementSizeBytes;
91+
const size_t lineSize = eSize * w;
9292

9393
//ALOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes);
9494

9595
if ((lineSize * h) != sizeBytes) {
96-
ALOGE("Allocation size mismatch, expected %i, got %i", (lineSize * h), sizeBytes);
96+
ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
9797
rsAssert(!"Allocation::subData called with mismatched size");
9898
return;
9999
}
@@ -104,12 +104,12 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod,
104104

105105
void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
106106
uint32_t lod, RsAllocationCubemapFace face,
107-
uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes) {
107+
uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes) {
108108
}
109109

110110
void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
111-
uint32_t cIdx, uint32_t sizeBytes) {
112-
uint32_t eSize = mHal.state.elementSizeBytes;
111+
uint32_t cIdx, size_t sizeBytes) {
112+
size_t eSize = mHal.state.elementSizeBytes;
113113

114114
if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
115115
ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
@@ -125,7 +125,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
125125

126126
const Element * e = mHal.state.type->getElement()->getField(cIdx);
127127
if (sizeBytes != e->getSizeBytes()) {
128-
ALOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes());
128+
ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
129129
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
130130
return;
131131
}
@@ -135,8 +135,8 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
135135
}
136136

137137
void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
138-
const void *data, uint32_t cIdx, uint32_t sizeBytes) {
139-
uint32_t eSize = mHal.state.elementSizeBytes;
138+
const void *data, uint32_t cIdx, size_t sizeBytes) {
139+
size_t eSize = mHal.state.elementSizeBytes;
140140

141141
if (x >= mHal.state.dimensionX) {
142142
ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
@@ -159,7 +159,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
159159
const Element * e = mHal.state.type->getElement()->getField(cIdx);
160160

161161
if (sizeBytes != e->getSizeBytes()) {
162-
ALOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes());
162+
ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
163163
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
164164
return;
165165
}
@@ -249,7 +249,7 @@ void Allocation::writePackedData(const Type *type,
249249
delete[] sizeUnpadded;
250250
}
251251

252-
void Allocation::unpackVec3Allocation(const void *data, uint32_t dataSize) {
252+
void Allocation::unpackVec3Allocation(const void *data, size_t dataSize) {
253253
const uint8_t *src = (const uint8_t*)data;
254254
uint8_t *dst = (uint8_t*)getPtr();
255255

@@ -519,13 +519,13 @@ void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t
519519
}
520520

521521
void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
522-
const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
522+
const void *data, size_t sizeBytes, size_t eoff) {
523523
Allocation *a = static_cast<Allocation *>(va);
524524
a->elementData(rsc, x, y, data, eoff, sizeBytes);
525525
}
526526

527527
void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
528-
const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
528+
const void *data, size_t sizeBytes, size_t eoff) {
529529
Allocation *a = static_cast<Allocation *>(va);
530530
a->elementData(rsc, x, data, eoff, sizeBytes);
531531
}

libs/rs/rsAllocation.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,16 +80,16 @@ class Allocation : public ObjectBase {
8080
void resize1D(Context *rsc, uint32_t dimX);
8181
void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY);
8282

83-
void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, uint32_t sizeBytes);
83+
void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, size_t sizeBytes);
8484
void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
85-
uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
85+
uint32_t w, uint32_t h, const void *data, size_t sizeBytes);
8686
void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face,
87-
uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
87+
uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes);
8888

8989
void elementData(Context *rsc, uint32_t x,
90-
const void *data, uint32_t elementOff, uint32_t sizeBytes);
90+
const void *data, uint32_t elementOff, size_t sizeBytes);
9191
void elementData(Context *rsc, uint32_t x, uint32_t y,
92-
const void *data, uint32_t elementOff, uint32_t sizeBytes);
92+
const void *data, uint32_t elementOff, size_t sizeBytes);
9393

9494
void read(void *data);
9595

@@ -138,7 +138,7 @@ class Allocation : public ObjectBase {
138138

139139
uint32_t getPackedSize() const;
140140
static void writePackedData(const Type *type, uint8_t *dst, const uint8_t *src, bool dstPadded);
141-
void unpackVec3Allocation(const void *data, uint32_t dataSize);
141+
void unpackVec3Allocation(const void *data, size_t dataSize);
142142
void packVec3Allocation(OStream *stream) const;
143143
};
144144

0 commit comments

Comments
 (0)