Comments (7)
I don't see anything wrong with your usage.
The interesting thing here is that you say it fails only randomly or occasionally. Otherwise I would immediately suspect a miscompilation of some kind.
Are you able to get a backtrace?
make: *** [test] Error 8
56 - Hash.SHA3 (ILLEGAL)
could this be related to a SIGILL? I'm wondering if we are somehow jumping to the BMI2 enabled codepath on a machine that doesn't support it.
from botan.
I successfully reproduced the crash in my fork, and after fixing the UB I pointed out, the crash seems to go away. Even running the unit tests many times in a single build job and/or restarting the build job several times didn't trigger the crash anymore. When I re-introduce the UB it comes back quite consistently.
Even under extreme conditions, the object size cannot be smaller then the data I declared.
Technically, I agree with you. And unfortunately, I can't explain why this UB seems to cause these spurious crashes. I'm going to blame some compiler optimizations going rogue.
Please try the fix in your branch.
from botan.
here's the backtrace I'm able to get. I added a signal handler to catch SIGILL. But don't have the debug symbols for Botan. Looks it jumped to NULL?
0 hash_unittest 0x000000010f9c1380 _ZZ4mainENK3$_0clEi + 32
1 hash_unittest 0x000000010f9c1359 _ZZ4mainEN3$_08__invokeEi + 9
2 libsystem_platform.dylib 0x00007ff812e90dfd _sigtramp + 29
3 ??? 0x0000000000000000 0x0 + 0
4 libbotan-3.2.2.0.dylib 0x00000001102a7a9f _ZN5Botan18Keccak_Permutation7permuteEv + 89
5 libbotan-3.2.2.0.dylib 0x0000000110239c61 _ZN5Botan5SHA_312final_resultENSt3__14spanIhLm18446744073709551615EEE + 31
6 hash_unittest 0x000000010f9c2dc2 _ZN7trantor5utils4sha3EPKvm + 98
7 hash_unittest 0x000000010f9c09dc _ZN14Hash_SHA3_Test8TestBodyEv + 60
8 hash_unittest 0x000000010fa1a06b _ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc + 123
9 hash_unittest 0x000000010f9def4a _ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc + 106
10 hash_unittest 0x000000010f9dee93 _ZN7testing4Test3RunEv + 195
11 hash_unittest 0x000000010f9dfef2 _ZN7testing8TestInfo3RunEv + 290
12 hash_unittest 0x000000010f9e0fcd _ZN7testing9TestSuite3RunEv + 317
13 hash_unittest 0x000000010f9f027d _ZN7testing8internal12UnitTestImpl11RunAllTestsEv + 1005
14 hash_unittest 0x000000010fa1eeab _ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc + 123
15 hash_unittest 0x000000010f9efc2a _ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc + 106
16 hash_unittest 0x000000010f9efb15 _ZN7testing8UnitTest3RunEv + 197
17 hash_unittest 0x000000010f9c1156 main + 54
18 dyld 0x000000011beac52e start + 462
from botan.
I noticed that you're using a sort-of strong type to write the output value to. The type is defined as:
struct Hash256
{
unsigned char bytes[32];
};
... and you're using it like so:
template <typename Hash>
inline bool attemptHash(const std::string_view& name,
Hash& hash,
const void* data,
size_t len)
{
auto hashFunction = Botan::HashFunction::create(name);
// [...]
hashFunction->update((const unsigned char*)data, len);
hashFunction->final((unsigned char*)&hash);
// ~~~ assumes that address of object is equal to address of buffer ~~~
return true;
}
Hash256 sha3(const void* data, size_t len)
{
Hash256 hash;
if (attemptHash("SHA-3(256)", hash, data, len))
return hash;
// [...]
return hash
}
You're assuming that the address of the member bytes
is always equal to the address of the object hash
. Now, I'm not saying that this is illegal and must be the cause of the sporadic crashes. Nevertheless, it strikes me as quite unusual, to be honest.
Maybe explicitly take the address of hash.bytes
(in attemptHash
) at least?
from botan.
You are right but I think it is unrelated. Even under extreme conditions, the object size cannot be smaller then the data I declared. Even if there's a huge buffer between the beginning of the object and the data, it will still be valid memory.
from botan.
@marty1885 Any news here? Otherwise, I'd like to close the issue
from botan.
Hey, sorry for the delay. It was CNY and stuff. I made a new branch and applied the changes. Still having the issue. PR is on the following link
from botan.
Related Issues (20)
- L HOT 1
- botan 3.3.0 fails to build on powerpc G4 HOT 3
- [2.19.4] Microsoft C++ error: Botan::Invalid_Argument in Botan::Cipher_Mode::create(...) HOT 5
- Request to add: Catena, Lyra2, Makwa, yescrypt HOT 2
- test failure in 2.19.4: dh_invalid HOT 4
- Need to upgrade CodeQL action
- Certstore system tests fail if certificates are not installed. HOT 1
- Doxygen output includes full file paths
- Odd CLI test failure on MacOS 14 runners
- build failure on armv7 with latest 3.4.0 release HOT 2
- Cancel CodeQL/CiFuzz jobs when a new commit is pushed
- Why do PK_Ops classes return secure_vector for non-private information
- Botan doesn't support large OIDs HOT 1
- ECDSA using SHAKE HOT 4
- Facing retransmission issue while adding delay in the server side in the DTLS implementation
- Invalid BER decoding of OIDs HOT 1
- `./botan tls_server` is lacking a `--trusted-cas=` argument HOT 7
- Replace BigInt based elliptic curve library
- Centralize 'integralish' concept and strong-type unwrapping
- Amalgamation SHA3 missing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from botan.