Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VeraCrypt fails at runtime when built with -D_GLIBCXX_ASSERTIONS #896

Closed
peterlobster opened this issue Feb 15, 2022 · 6 comments
Closed
Labels

Comments

@peterlobster
Copy link

peterlobster commented Feb 15, 2022

Expected behavior

Observed behavior

VeraCrypt crashes, when setting a password, using the "New Volume" wizard.

Screenshots

...
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = char; _Alloc = std::allocator<char>; std::vector<_Tp, _Alloc>::reference = char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)
...

Your Environment

Please tell us more about your environment

VeraCrypt version:
1.25.7

Operating system and version:
Linux localhost 5.15.19-gentoo #31 SMP Tue Feb 15 13:22:10 PST 2022 x86_64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz GenuineIntel GNU/Linux

System type:
x86

CFLAGS

CFLAGS="-march=native -O2 -pipe -D_FORTIFY_SOURCE=2 -falign-functions=32 -Wa,-mbranches-within-32B-boundaries -mfpmath=sse -fgraphite-identity -floop-nest-optimize -flto=auto -ffat-lto-objects -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt -fipa-pta -fexceptions -feliminate-unused-debug-types -fasynchronous-unwind-tables -Wall -Wformat -Wformat-security -ggdb3 -grecord-gcc-switches -Wl,-O2 -Wl,--as-needed -Wl,-z,now,-z,relro -Wl,--sort-common -Wl,--enable-new-dtags"

CXXFLAGS

CXXFLAGS="-march=native -O2 -pipe -D_FORTIFY_SOURCE=2 -falign-functions=32 -Wa,-mbranches-within-32B-boundaries -mfpmath=sse -fgraphite-identity -floop-nest-optimize -flto=auto -ffat-lto-objects -fno-semantic-interposition -fdevirtualize-at-ltrans -fno-plt -fipa-pta -fexceptions -feliminate-unused-debug-types -fasynchronous-unwind-tables -Wall -Wformat -Wformat-security -ggdb3 -grecord-gcc-switches -D_GLIBCXX_ASSERTIONS"
@peterlobster
Copy link
Author

peterlobster commented Feb 15, 2022

So it turns out neither VeraCrypt does like to being built with -D_GLIBCXX_ASSERTIONS. It also doesn't like GTK built with -D_GLIBCXX_ASSERTIONS. I turned them off, and was able to resolve this but it doesn't seem like a correct fix for the issue...

Also reported to Upstream: https://bugs.gentoo.org/833444

Original VeraCrypt crash
veracrypt-output.txt
backtrace.log

@thesamesam
Copy link

Snippet of backtrace:

Thread 1 "veracrypt" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
49	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
#1  0x00007ffff70da577 in __GI_abort () at abort.c:79
#2  0x0000555555640ac4 in std::__replacement_assert(char const*, int, char const*, char const*)
    (__file=<optimized out>, __line=<optimized out>, __function=<optimized out>, __condition=<optimized out>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/x86_64-pc-linux-gnu/bits/c++config.h:514
#3  0x000055555576e275 in std::vector<char, std::allocator<char> >::operator[](unsigned long) (this=<optimized out>, __n=<optimized out>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/bits/stl_vector.h:1043
#4  std::vector<char, std::allocator<char> >::operator[](unsigned long) (__n=0, this=0x7fffffffd090, this=<optimized out>, __n=<optimized out>)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include/g++-v11/bits/stl_vector.h:1043
#5  VeraCrypt::Process::Execute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int, VeraCrypt::ProcessExecFunctor*, VeraCrypt::Buffer const*) (processName="mkfs.ext4", arguments=<optimized out>, timeOut=-1, execFunctor=<optimized out>, inputData=0x7fffffffd100) at ../Platform/Unix/Process.cpp:144
#6  0x00005555556fb3bd in VeraCrypt::VolumeCreationOptions::FilesystemType::IsFsFormatterPresent(VeraCrypt::VolumeCreationOptions::FilesystemType::Enum) (fsType=<optimized out>)
    at /var/tmp/portage/app-crypt/veracrypt-1.25.7/work/VeraCrypt-VeraCrypt_1.25.7/src/Core/VolumeCreator.h:109

-DGLIBCXX_ASSERTIONS enables assertions within libstdc++ (mainly bounds checking).

@peterlobster peterlobster changed the title gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkRadioButton VeraCrypt fails at runtime when built with -D_GLIBCXX_ASSERTIONS Feb 16, 2022
idrassi added a commit that referenced this issue Feb 18, 2022
…an assert in libstdc++.

The variable has enough capacity so pointer &buffer[0] is valid but since clear method was called, we are not supposed to access element at index 0.
Related to Github issue #896
@idrassi
Copy link
Member

idrassi commented Feb 18, 2022

Thank you for reporting this issue.
I have pushed a fix (b52ce86): buffer.clear () was called which caused the size of buffer to become zero but the pointer &buffer[0] is valid since buffer capacity is 4096. Nevertheless, we should not call clear on buffer and so removing this line fixes the libstdc++ assert.

Let me know if you encounter other issues.

@gktrk
Copy link
Contributor

gktrk commented Feb 18, 2022

@idrassi if the intent of .clear() is to zero-out the buffer, vector has a fill constructor in the form of vector<char> buffer(4096, 0) that would accomplish the same thing without the need for an extra call. If that's not the intent, I wonder why .clear() is required there, it's not inside a loop or anything.

@idrassi
Copy link
Member

idrassi commented Feb 18, 2022

clear needed to be called for the other vector variables and it was called on buffer variable by mistake. Nevertheless the code was working thanks to how vector class allocates memory (capacity was 4096 even if size was 0).
The new commit fixed this mistake and now buffer size remains equal to its capacity.

@idrassi
Copy link
Member

idrassi commented Feb 20, 2022

The fix is included in version 1.25.9 that has just been released.
Feel free to reopen in case of further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants