<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>    On my machine, when running x264 with <b>4 threads</b> (sandbox version, git HEAD d4099dd4c722f52c4f3c14575d7d39eb8fadb97f), it may cause a heap-buffer-overflow (read) at encoder/me.c:406.<br></div><div><br></div><div>$ ./x264-asan/install/bin/x264 --threads 4 --quiet --output /dev/null hbo_me.c:406_1</div><div><div>=================================================================</div><div>==23250==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000030904 at pc 0x000000755471 bp 0x7fadac672df0 sp 0x7fadac672de8</div><div>READ of size 2 at 0x621000030904 thread T4</div><div>    #0 0x755470 in x264_8_me_search_ref /home/hongxu/work/x264/x264-asan/encoder/me.c:406:13</div><div>    #1 0x6df538 in mb_analyse_inter_p16x16 /home/hongxu/work/x264/x264-asan/encoder/analyse.c:1275:13</div><div>    #2 0x6df538 in x264_8_macroblock_analyse /home/hongxu/work/x264/x264-asan/encoder/analyse.c:3026</div><div>    #3 0x59f274 in slice_write /home/hongxu/work/x264/x264-asan/encoder/encoder.c:2775:9</div><div>    #4 0x591bee in slices_write /home/hongxu/work/x264/x264-asan/encoder/encoder.c:3116:13</div><div>    #5 0x5a9fdf in threadpool_thread_internal /home/hongxu/work/x264/x264-asan/common/threadpool.c:69:20</div><div>    #6 0x5fefeb in x264_stack_align (/home/hongxu/work/x264/x264-asan/install/bin/x264+0x5fefeb)</div><div><br></div><div>0x621000030904 is located 2 bytes to the right of 4098-byte region [0x62100002f900,0x621000030902)</div><div>allocated by thread T0 here:</div><div>    #0 0x4d4948 in __interceptor_memalign.localalias.1 (/home/hongxu/work/x264/x264-asan/install/bin/x264+0x4d4948)</div><div>    #1 0x548fcc in x264_malloc /home/hongxu/work/x264/x264-asan/common/base.c:124:21</div><div><br></div><div>Thread T4 created by T0 here:</div><div>    #0 0x4377a0 in pthread_create (/home/hongxu/work/x264/x264-asan/install/bin/x264+0x4377a0)</div><div>    #1 0x5a96e9 in x264_8_threadpool_init /home/hongxu/work/x264/x264-asan/common/threadpool.c:111:13</div><div><br></div><div>SUMMARY: AddressSanitizer: heap-buffer-overflow /home/hongxu/work/x264/x264-asan/encoder/me.c:406:13 in x264_8_me_search_ref</div><div>Shadow bytes around the buggy address:</div><div>  0x0c427fffe0d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</div><div>  0x0c427fffe0e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</div><div>  0x0c427fffe0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</div><div>  0x0c427fffe100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</div><div>  0x0c427fffe110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</div><div>=>0x0c427fffe120:[02]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>  0x0c427fffe130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>  0x0c427fffe140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>  0x0c427fffe150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>  0x0c427fffe160: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>  0x0c427fffe170: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa</div><div>Shadow byte legend (one shadow byte represents 8 application bytes):</div><div>  Addressable:           00</div><div>  Partially addressable: 01 02 03 04 05 06 07 </div><div>  Heap left redzone:       fa</div><div>  Freed heap region:       fd</div><div>  Stack left redzone:      f1</div><div>  Stack mid redzone:       f2</div><div>  Stack right redzone:     f3</div><div>  Stack after return:      f5</div><div>  Stack use after scope:   f8</div><div>  Global redzone:          f9</div><div>  Global init order:       f6</div><div>  Poisoned by user:        f7</div><div>  Container overflow:      fc</div><div>  Array cookie:            ac</div><div>  Intra object redzone:    bb</div><div>  ASan internal:           fe</div><div>  Left alloca redzone:     ca</div><div>  Right alloca redzone:    cb</div><div>==23250==ABORTING</div><div>[1]    23250 abort      ./x264-asan/install/bin/x264 --threads 4 --quiet --output /dev/null</div></div><div><br></div><div>  When running with 1,2,3 threads, it crashes at different places such as encoder/me.c:244.</div><div>  When running with 5 or more threads, everything seems fine.</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><font color="#313131" face="Arial, sans-serif"><span style="font-size:12px">Best Regards,</span></font><div><font color="#313131" face="Arial, sans-serif"><span style="font-size:12px">Hongxu</span></font></div></div></div></div></div></div></div></div></div></div>