-
Notifications
You must be signed in to change notification settings - Fork 273
Spurious malloc behavior for large allocations #6130
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
Comments
The counterexample when running State 70 file main.c function main line 10 thread 0
----------------------------------------------------
ptr_end=dynamic_object1 + -36028797018963968l (00000010 10000000 00000000 00000000 00000000 00000000 00000000 00000000)
Violated property:
file main.c function main line 11 thread 0
pointer relation: pointer outside object bounds in ptr_end
POINTER_OFFSET(ptr_end) >= 0l && OBJECT_SIZE(ptr_end) >= (unsigned long int)POINTER_OFFSET(ptr_end) Why does CBMC have a negative number as offset in this case? |
IMO, the most worrying issue here is the crash. CBMC should never crash. This PR looks related: #5210. $ cat ~/test.c
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
int main () {
size_t size;
size = SIZE_MAX;
uint8_t *ptr = malloc(size);
__CPROVER_assume(ptr != NULL);
uint8_t *ptr_end = ptr + size;
assert(ptr <= ptr_end);
}
$ cbmc ~/test.c
CBMC version 5.30.0 (cbmc-5.24.0-606-g0ea7f13c4-dirty) 64-bit x86_64 macos
Parsing /Users/saspadhi/test.c
Converting
Type-checking test
Generating GOTO Program
Adding CPROVER library (x86_64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 8 object bits, 56 offset bits (default)
Starting Bounded Model Checking
Runtime Symex: 0.0242014s
size of program expression: 85 steps
simple slicing removed 5 assignments
Generated 1 VCC(s), 1 remaining after simplification
Runtime Postprocess Equation: 5.2114e-05s
Passing problem to propositional reduction
converting SSA
array too large for flattening
$ cbmc --malloc-fail-assert ~/test.c | tail
** Results:
/Users/saspadhi/test.c function main
[main.assertion.1] line 11 assertion ptr <= ptr_end: SUCCESS
<builtin-library-malloc> function malloc
[malloc.assertion.1] line 26 max allocation size exceeded: FAILURE
[malloc.assertion.2] line 31 max allocation may fail: SUCCESS
** 1 of 3 failed (2 iterations)
VERIFICATION FAILED |
Without the flag |
@SaswatPadhi Could you please elaborate on the following:
Which of the examples provided above results in some kind of "crash?" |
@feliperodri @SaswatPadhi Thank you for the detailed report. Apart from my above question: I'll try to figure out whether there are bugs hidden in here that aren't just down to the object:offset encoding. That I'm trying to get rid of in #1086, which I'm (very slowly) making progress on. |
I meant when running CBMC without
|
This is a duplicate of PR diffblue#2108. This is here for alternative author management. Fixes diffblue#6130
CBMC version:
develop
Operating system: macOs Majave
Exact command line resulting in the issue:
cbmc main.c --malloc-may-fail --malloc-fail-null --pointer-overflow-check --pointer-check
What behaviour did you expect: Consistent behaviour using malloc for large allocations.
What happened instead:
Consider the following example.
Running this example with
cbmc main.c --malloc-may-fail --malloc-fail-null --pointer-overflow-check --pointer-check
leads to verification failure.Running this example with
cbmc main.c --pointer-overflow-check --pointer-check
leads to another kind of verification failure.If we include line 7, we get different results too.
Using
cbmc main.c --malloc-may-fail --malloc-fail-null --pointer-overflow-check --pointer-check
.Using
cbmc main.c --pointer-overflow-check --pointer-check
.Why do we have completely different results here? Am I missing something? What is CBMC behaviour for allocation attempts where
size
is larger than__CPROVER_max_malloc_size
? What is the definition of__CPROVER_max_malloc_size
?Often, we need to use in our proofs the following trick
Why should this be even necessary here? Wouldn't malloc take care of such cases?
cc. @tautschnig @SaswatPadhi
The text was updated successfully, but these errors were encountered: