sosy-lab / sv-benchmarks

Collection of Verification Tasks (MOVED, please follow the link)
https://gitlab.com/sosy-lab/benchmarking/sv-benchmarks
184 stars 169 forks source link

Wrong verdicts in CWE369*bad_version2 #1227

Closed peterschrammel closed 3 years ago

peterschrammel commented 3 years ago

These three benchmarks seem to have verdict TRUE instead FALSE.

I've tried with a cut down version, which captures the core logic:

public class Cwe {
  public static void foo(float data, float offset) {
    if (offset < 1.0f)
      return;
    data = data - offset;
    int result = (int) (100.0 / data);
    if (1 < data || data <= 0) {
      assert result < 100;
    }
  }
}

The assertion is unreachable according to JBMC.

It's also unreachable in CBMC using the corresponding C version:

#include <assert.h>

void foo(float data, float offset)
{
  if (offset < 1.0f)
    return;
  data = data - offset;
  int result = (int) (100.0 / data);
  if (1 < data || data <= 0) {
    assert(result < 100);
  }
}

Does anyone have a counterexample for these benchmarks?

@mmuesly

mmuesly commented 3 years ago
public class Cwe {
  public static void foo(float data, float offset) {
    if (offset < 1.0f)
      return;
    data = data - offset;
    int result = (int) (100.0 / data);
    if (1 < data || data <= 0) {
      assert result < 100;
    }
  }

  public static void main (String[] args){
    foo(123, 123);
  }

}

running with java -ea Cwe leads to:

maltemues in /tmp > java -ea Cwe 
Exception in thread "main" java.lang.AssertionError
    at Cwe.foo(Cwe.java:8)
    at Cwe.main(Cwe.java:13)

See float division rules in Java and "Narrowing Primitive Conversion" for more context in the JVM leading to this AssertionError.

I reject the PR.

peterschrammel commented 3 years ago

Thanks, @mmuesly. This proves that the problem is clearly in our tool.