[GMP] Factor out more detailed CheckDimensions function for CreateFrame.

This commit is contained in:
Moonchild 2024-10-02 10:34:38 +02:00 committed by roytam1
commit b848a924bc
2 changed files with 33 additions and 5 deletions

View file

@ -89,6 +89,34 @@ GMPVideoi420FrameImpl::CheckFrameData(const GMPVideoi420FrameData& aFrameData)
return true;
}
bool
GMPVideoi420FrameImpl::CheckDimensions(int32_t aWidth, int32_t aHeight,
int32_t aStride_y,
int32_t aStride_u,
int32_t aStride_v, int32_t aSize_y,
int32_t aSize_u, int32_t aSize_v) {
if (aWidth < 1 || aHeight < 1 || aStride_y < aWidth || aSize_y < 1 ||
aSize_u < 1 || aSize_v < 1) {
return false;
}
auto halfWidth = (CheckedInt<int32_t>(aWidth) + 1) / 2;
if (!halfWidth.isValid() || aStride_u < halfWidth.value() ||
aStride_v < halfWidth.value()) {
return false;
}
auto height = CheckedInt<int32_t>(aHeight);
auto halfHeight = (height + 1) / 2;
auto minSizeY = height * aStride_y;
auto minSizeU = halfHeight * aStride_u;
auto minSizeV = halfHeight * aStride_v;
if (!minSizeY.isValid() || !minSizeU.isValid() || !minSizeV.isValid() ||
minSizeY.value() > aSize_y || minSizeU.value() > aSize_u ||
minSizeV.value() > aSize_v) {
return false;
}
return true;
}
bool
GMPVideoi420FrameImpl::CheckDimensions(int32_t aWidth, int32_t aHeight,
int32_t aStride_y, int32_t aStride_u, int32_t aStride_v)
@ -179,11 +207,8 @@ GMPVideoi420FrameImpl::CreateFrame(int32_t aSize_y, const uint8_t* aBuffer_y,
MOZ_ASSERT(aBuffer_u);
MOZ_ASSERT(aBuffer_v);
if (aSize_y < 1 || aSize_u < 1 || aSize_v < 1) {
return GMPGenericErr;
}
if (!CheckDimensions(aWidth, aHeight, aStride_y, aStride_u, aStride_v)) {
if (!CheckDimensions(aWidth, aHeight, aStride_y, aStride_u, aStride_v,
aSize_y, aSize_u, aSize_v)) {
return GMPGenericErr;
}

View file

@ -65,6 +65,9 @@ public:
void ResetSize() override;
private:
bool CheckDimensions(int32_t aWidth, int32_t aHeight, int32_t aStride_y,
int32_t aStride_u, int32_t aStride_v, int32_t aSize_y,
int32_t aSize_u, int32_t aSize_v);
bool CheckDimensions(int32_t aWidth, int32_t aHeight,
int32_t aStride_y, int32_t aStride_u, int32_t aStride_v);