Skip to content

Check alignment in aligned_alloc calls #380

@suyash67

Description

@suyash67

The alignment in some of the aligned_alloc calls is incorrect. For example, on the following line:

bucket_empty_status = (bool*)(aligned_alloc(64, num_threads * num_buckets * sizeof(bool)));

The first argument is alignment = 64 and num_buckets = 16. So when we're not using multi-threading, the second argument is size = 1 * 16 * 1 = 16. This error can only be triggered if ASAN is enabled.

=================================================================
==666590==ERROR: AddressSanitizer: invalid alignment requested in aligned_alloc: 64, alignment must be a power of two and the requested size 0x20 must be a multiple of alignment (thread T0)
    #0 0x561277be50d2 in __interceptor_aligned_alloc (/mnt/user-data/suyash/projects/barretenberg/cpp/build/bin/examples_tests+0xe40d2) (BuildId: 9b00bdd4e2e236c81e9abacc0232acbc5968721e)
    #1 0x56127842cdcb in barretenberg::scalar_multiplication::pippenger_runtime_state::pippenger_runtime_state(unsigned long) (/mnt/user-data/suyash/projects/barretenberg/cpp/build/bin/examples_tests+0x92bdcb) (BuildId: 9b00bdd4e2e236c81e9abacc0232acbc5968721e)

==666590==HINT: if you don't care about these errors you may set allocator_may_return_null=1
SUMMARY: AddressSanitizer: invalid-aligned-alloc-alignment (/mnt/user-data/suyash/projects/barretenberg/cpp/build/bin/examples_tests+0xe40d2) (BuildId: 9b00bdd4e2e236c81e9abacc0232acbc5968721e) in __interceptor_aligned_alloc
==666590==ABORTING

We should check if such issues also occur elsewhere in the code and make sure we don't have any memory related problems in barretenberg.

Metadata

Metadata

Assignees

Labels

auditThings to do during the next audit

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions