Skip to content

Fortify warning: memcpy bound exceeds object size in esign.cpp when building with clang22 #1338

@scc-tw

Description

@scc-tw

Hello maintainers,

When building Crypto++ with clang22 (flags: -DNDEBUG -g2 -O3 -fPIC -fno-devirtualize -pthread -pipe), I observed a fortify/stringop-overflow warning from memcpy at compilation of esign.cpp. I would appreciate your advice or triage for this warning.


Warning excerpt:

In file included from /usr/include/string.h:548,
                 from /usr/include/c++/14/cstring:43,
                 from stdcpp.h:63,
                 from cryptlib.h:106,
                 from esign.h:10,
                 from esign.cpp:11:
In function 'void* memcpy(void*, const void*, size_t)',
    inlined from 'virtual void CryptoPP::InvertibleESIGNFunction::GenerateRandom(CryptoPP::RandomNumberGenerator&, const CryptoPP::NameValuePairs&)' at esign.cpp:115:14:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]

Context & Source:

if (param.GetValue("Seed", seedParam))
{
    seed.resize(seedParam.size() + 4);
    std::memcpy(seed + 4, seedParam.begin(), seedParam.size());
    // ...
}

(see full file: esign.cpp)


Notes:

  • I have not investigated the root cause.
  • I am not proposing a patch at this time; this is a tracking/triage report.

Steps to reproduce:

  1. Build Crypto++ with clang22 and the flags listed above.
  2. Observe the warning in the compilation output for esign.cpp.

Many thanks for your attention!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions