mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-08 17:17:15 +00:00
add explicit barriers for buffer overread and overrwrite (#6484)
Co-authored-by: Ori Levari <orlevari@microsoft.com>
This commit is contained in:
parent
7f5731741d
commit
76f5d9edc6
2 changed files with 12 additions and 8 deletions
|
|
@ -41,7 +41,6 @@ namespace ImageTestHelper {
|
|||
wf::IMemoryBufferReference reference = spBitmapBuffer.CreateReference();
|
||||
auto spByteAccess = reference.as<::Windows::Foundation::IMemoryBufferByteAccess>();
|
||||
spByteAccess->GetBuffer(&pData, &size);
|
||||
|
||||
uint32_t height = softwareBitmap.PixelHeight();
|
||||
uint32_t width = softwareBitmap.PixelWidth();
|
||||
|
||||
|
|
@ -53,14 +52,15 @@ namespace ImageTestHelper {
|
|||
com_ptr<ITensorNative> itn = tf.as<ITensorNative>();
|
||||
itn->GetBuffer(reinterpret_cast<BYTE**>(&pCPUTensor), &uCapacity);
|
||||
if (BitmapPixelFormat::Bgra8 == GetPixelFormat(modelPixelFormat)) {
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (float)pData[i];
|
||||
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
|
||||
pCPUTensor[(height * width * 2) + pixelInd] = (float)pData[i + 2];
|
||||
}
|
||||
} else if (BitmapPixelFormat::Rgba8 == GetPixelFormat(modelPixelFormat)) {
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (float)pData[i + 2];
|
||||
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
|
||||
|
|
@ -99,14 +99,15 @@ namespace ImageTestHelper {
|
|||
uint32_t height = softwareBitmap.PixelHeight();
|
||||
uint32_t width = softwareBitmap.PixelWidth();
|
||||
if (BitmapPixelFormat::Bgra8 == GetPixelFormat(modelPixelFormat)) {
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (float)pData[i];
|
||||
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
|
||||
pCPUTensor[(height * width * 2) + pixelInd] = (float)pData[i + 2];
|
||||
}
|
||||
} else if (BitmapPixelFormat::Rgba8 == GetPixelFormat(modelPixelFormat)) {
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (float)pData[i + 2];
|
||||
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
|
||||
|
|
|
|||
|
|
@ -816,7 +816,8 @@ static void Scenario22ImageBindingAsCPUTensor() {
|
|||
|
||||
uint32_t height = softwareBitmap.PixelHeight();
|
||||
uint32_t width = softwareBitmap.PixelWidth();
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (float)pData[i];
|
||||
pCPUTensor[(height * width) + pixelInd] = (float)pData[i + 1];
|
||||
|
|
@ -887,7 +888,8 @@ static void Scenario22ImageBindingAsGPUTensor() {
|
|||
|
||||
uint32_t height = softwareBitmap.PixelHeight();
|
||||
uint32_t width = softwareBitmap.PixelWidth();
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
for (UINT32 i = 0; i < size - 2; i += 4) {
|
||||
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
|
||||
UINT32 pixelInd = i / 4;
|
||||
pCPUTensor[pixelInd] = (FLOAT)pData[i];
|
||||
pCPUTensor[(height * width) + pixelInd] = (FLOAT)pData[i + 1];
|
||||
|
|
@ -1494,7 +1496,8 @@ static void BindMultipleCPUBuffersAsInputs(LearningModelDeviceKind kind) {
|
|||
green_byteaccess->GetBuffer(reinterpret_cast<BYTE**>(&green_data), &frame_size);
|
||||
blue_byteaccess->GetBuffer(reinterpret_cast<BYTE**>(&blue_data), &frame_size);
|
||||
|
||||
for (UINT32 i = 0; i < size; i += 4) {
|
||||
for (UINT32 i = 0; i < size - 2 && i / 4 < frame_size; i += 4) {
|
||||
// loop condition is i < size - 2 to avoid potential for extending past the memory buffer
|
||||
UINT32 pixelInd = i / 4;
|
||||
red_data[pixelInd] = (float)data[i];
|
||||
green_data[pixelInd] = (float)data[i + 1];
|
||||
|
|
|
|||
Loading…
Reference in a new issue