Bug 452072 - false positive from wmemcmp_avx2_movbe (glibc-2.34 or later?)
Summary: false positive from wmemcmp_avx2_movbe (glibc-2.34 or later?)
Status: RESOLVED DUPLICATE of bug 397083
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (other bugs)
Version First Reported In: 3.18.1
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-30 10:38 UTC by takimoto-j
Modified: 2024-04-11 18:24 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
output of "valgrind -v ./a.out" (9.41 KB, text/plain)
2022-03-30 10:38 UTC, takimoto-j
Details

Note You need to log in before you can comment on or make changes to this bug.
Description takimoto-j 2022-03-30 10:38:46 UTC
Created attachment 147840 [details]
output of "valgrind -v ./a.out"

SUMMARY
wmemcmp(s1, s2, n) gives false positive even if n is smaller than the allocated size of s1 and s2

STEPS TO REPRODUCE
1. compile the following C source (test.c):

#include <stdlib.h>
#include <wchar.h>
int main()  {
    wchar_t *a, *b;
    int ret;
    a = (wchar_t*)calloc(3, sizeof(wchar_t));
    b = (wchar_t*)calloc(3, sizeof(wchar_t));
    ret = wmemcmp(a, b, 2);
    free(a);
    free(b);
    return ret;
}

2. valgrind ./a.out

OBSERVED RESULT
Invalid read of size 32
   at 0x49EB499: __wmemcmp_avx2_movbe (memcmp-avx2-movbe.S:412)
   by 0x40118B: main (test.c:8)
 Address 0x4a75090 is 0 bytes inside a block of size 12 alloc'd
   at 0x4849464: calloc (vg_replace_malloc.c:1328)
   by 0x40116F: main (test.c:7)

Output of 'valglind -v ./a.out' is in log.txt.

EXPECTED RESULT
no error

SOFTWARE/OS VERSIONS
Fedora-35

ADDITIONAL INFORMATION
CPU is x86_64 with AVX2.
Fedora-35 uses glibc-2.34.
Same problem in the latest Arch Linux (glibc-2.35),
but no problem in Fedora-34 (glibc-2.33).
Comment 1 Paul Floyd 2024-04-11 18:24:01 UTC

*** This bug has been marked as a duplicate of bug 397083 ***