Check buffer size when frameWidth * frameHeight bigger than allocated buffer size#21170
Check buffer size when frameWidth * frameHeight bigger than allocated buffer size#21170alalek merged 5 commits intoopencv:4.xfrom
Conversation
…than allocated buffer size
- issue nubmer opencv#21149 report, some android 12 device, allocated bufferSize is too small for the retrieve frame, so change logic for debugging
alalek
left a comment
There was a problem hiding this comment.
Thank you for contribution!
Please take a look on comments below.
| if (info.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) { | ||
| if (frameWidth * frameHeight * 3 / 2 > bufferSize) | ||
| { | ||
| if (bufferSize == 3110400 && (frameWidth == 1920 && frameHeight == 1088) || frameWidth == 1088 && frameHeight == 1920) |
There was a problem hiding this comment.
|| frameWidth == 1088 && frameHeight == 1920
Priority brackets is necessary in condition with &&/|| mess.
Please use this work around code with shorter conditions to support both 1920x1088 / 1088x1920 cases.
Please add link to the issue for this workaround code.
// WA: https://github.com/opencv/opencv/issues/21149
if (frameWidth * frameHeight * 3 / 2 > bufferSize)
{
if (bufferSize == 3110400 && frameWidth == 1920 && frameHeight == 1088)
{
frameHeight = 1080;
LOGV(...);
}
else if (bufferSize == 3110400 && frameWidth == 1088 && frameHeight == 1920`)
{
frameWidth = 1080;
LOGV(...);
}
else
{
LOGE(...);
return false;
}
}
There was a problem hiding this comment.
Thank you for update!
Please remove unnecessary whitespace: http://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/33151/steps/whitespace%20opencv/logs/stdio
Also please remove double space on this line:
else if(bufferSize == 3110400 && frameWidth == 1088 && frameHeight == 1920)
^^
There was a problem hiding this comment.
We still have whitespace issue: http://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/33152/steps/whitespace%20opencv/logs/stdio
modules/videoio/src/cap_android_mediandk.cpp:108: trailing whitespace.
+ {
^^^ 3 spaces here
| if (info.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) | ||
| { | ||
| LOGV("output EOS"); | ||
| sawOutputEOS = true; | ||
| } |
There was a problem hiding this comment.
Perhaps this code block should go first.
return false; above should not block sawOutputEOS = true; flag.
There was a problem hiding this comment.
Yes, Thanks your review, I will fix it and repush it!
delete double space about code convention
Check buffer size when frameWidth * frameHeight bigger than allocated buffer size
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.