<div dir="ltr"><div>Hi,<br></div>I'm developing an app which flips a frame in this way<br clear="all"><div><div><br></div><div>    frame->stride[0] *= -1;<br>    frame->stride[1] *= -1;<br>    frame->stride[2] *= -1;<br>    frame->data[0]    = frame->data[1] + frame->stride[0];<br>    frame->data[1]    = frame->data[2] + frame->stride[1];<br>    frame->data[2]    = frame->data[2] + (((frame->height >> desc->log2_chroma_h) - 1) * -frame->stride[2]);<br></div><div><br></div><div>and then proceeds to encode it with either x264 or x265.</div><div><br></div><div>When feeding this frame to x265_encode(), I get a crash in x265_upShift_16_avx2 at picyuv.cpp:322. While debugging I noticed that there is something wrong in the division for the input stride: for a 640x480 yuv 10 bit frame (with negative strides) the computed value is <span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline;float:none">9223372036854775168</span> instead of -640.</div><div><br></div><div>I believe the problem lies in the operation <span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline;float:none">pic.stride[0] / sizeof(*yShort) </span>where <span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline;float:none"></span>the result of every division is promoted to unsigned since<span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline;float:none"></span> sizeof() returns size_t (aka unsigned long). Unfortunately this issue is spread across the entire codebase, affecting every arithmetic operation whenever a stride is computed or updated. I think this was introduced four years ago in <a href="https://bitbucket.org/multicoreware/x265/commits/eadec14402d6">https://bitbucket.org/multicoreware/x265/commits/eadec14402d6</a>.<br></div><div><br></div><div>The solution would be to properly cast every sizeof() operation to ssize_t or int, or modify the internal functions to operate on bytes instead of pixels. The same frame fed to x264 is correctly encoded just fine.</div><div><br></div><div>Can anybody verify and apply a proper fix? Thank you<br></div><div><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline;float:none"></span></div><div>-- <br><div class="gmail_signature">Vittorio</div>
</div></div></div>