Skip to content

Commit

Permalink
Fix a potential memory allocation failure. (#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingpqi123 authored Sep 19, 2024
1 parent 6218a45 commit 68ad155
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/platform/ohos/OHOSVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,29 @@ std::shared_ptr<tgfx::ImageBuffer> OHOSVideoDecoder::onRenderFrame() {
OH_NativeBuffer_Unreference(hardwareBuffer);
}
} else {
if (videoStride == 0) {
if (videoStride == 0 || videoSliceHeight == 0) {
OH_AVFormat* format = OH_VideoDecoder_GetOutputDescription(videoCodec);
if (format) {
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_STRIDE, &videoStride);
OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_SLICE_HEIGHT, &videoSliceHeight);
} else {
}
if (videoStride == 0 || videoSliceHeight == 0) {
return nullptr;
}
yBufferSize = videoStride * videoSliceHeight;
uvBufferSize = codecBufferInfo.attr.size - yBufferSize;
yuvBuffer = std::make_shared<pag::YUVBuffer>();
yuvBuffer->data[0] = new uint8_t[yBufferSize];
yuvBuffer->data[1] = new uint8_t[uvBufferSize];
yuvBuffer->data[0] = new (std::nothrow) uint8_t[yBufferSize];
if (yuvBuffer->data[0] == nullptr) {
videoStride = 0;
return nullptr;
}
yuvBuffer->data[1] = new (std::nothrow) uint8_t[uvBufferSize];
if (yuvBuffer->data[1] == nullptr) {
delete[] yuvBuffer->data[0];
videoStride = 0;
return nullptr;
}
yuvBuffer->lineSize[0] = videoStride;
yuvBuffer->lineSize[1] = videoStride;
OH_AVFormat_Destroy(format);
Expand Down

0 comments on commit 68ad155

Please sign in to comment.