sagarpant1 / x265

GNU General Public License v2.0
0 stars 1 forks source link

Potential issue in source/common/scaler.cpp: Arithmetic Overflow in Expression #1

Open monocle-ai opened 4 years ago

monocle-ai commented 4 years ago

What is a Arithmetic Overflow? When a narrow type integral value was shifted left, multiplied, added, or subtracted and the result of that arithmetic operation was cast to a wider type value. If the operation overflowed the narrow type value, then data is lost. You can prevent this loss by converting the value to a wider type before the arithmetic operation.

1 instance of this defect were found in the following locations:


Instance 1 File : source/common/scaler.cpp Enclosing Function : initFromSrc@ScalerSlice@x265 https://github.com/sagarpant1/x265/blob/f7967350cb80e0eb7417f1738a992a2bb905c457/source/common/scaler.cpp#L1076 Issue in: lum y, lum h

Code extract:


    const int start[m_numSlicePlane] = { lumY, crY, crY, lumY };

    const int end[m_numSlicePlane] = { lumY + lumH, crY + crH, crY + crH, lumY + lumH };
 <------ HERE

    uint8_t *const src_[m_numSlicePlane] = { src[0] + (relative ? 0 : start[0]) * stride[0],

How can I fix it? Correct reference usage found in source/common/scaler.cpp at line 834. https://github.com/sagarpant1/x265/blob/f7967350cb80e0eb7417f1738a992a2bb905c457/source/common/scaler.cpp#L834 Code extract:


    for (lumY = 0; lumY < dstH; lumY++)
    {
        int crY = (int64_t)lumY * crDstH / dstH;
 <------ HERE
        int nextSlice = x265_max(lumFilterPos[lumY] + lumFilterSize - 1, ((crFilterPos[crY] + crFilterSize - 1) << crSubSample));
siva-msft commented 4 years ago

pred label 0