c++ - What are the dangers of floating point exceptions on invalid input? -


i ran fuzzying on dcraw , found floating point exception.

what dangers of this? reads length plen corrupted file , computes foo[i % plen]. if plen == 0 undefined standard , gcc throws floating point exception. edit: , exception not caught (this c) , program terminates.

should care? there scenario exploited or cause other bad things? 1 possible correct behaviour of code notice file corrupted , exist. how different throwing fpe , exiting?

(i'm surprised haven't found question on because seems basic me.)

if plen == 0 undefined standard ...

exactly. means, compiler free assume doesn't happen. code, example

int foo(int m, int n) {     if(n == 0) return m % n;     return 0; } 

is compiled to

foo:                                    # @foo     xorl    %eax, %eax     ret 

by clang -std=c99 -s -o2 on machine (intel x86). if branch assumed never entered , foo returns 0 unconditionally. no fpe, no crash. (i couldn't find similar small example gcc, unfortunately.)

... , gcc throws floating point exception.

not quite. that's cpu if code tries divide zero. but, said above, there no guarantee such code generated @ all.

i doubt gcc defines here (and couldn't find indicating in documentation).

should care? there scenario exploited or cause other bad things? 1 possible correct behaviour of code notice file corrupted , exist. how different throwing fpe , exiting?

you should care. bad luck, programme proceed wrong input file, see above.

and error message "invalid input file." nicer in opinion "floating-pointing exception.". former tells me (as end user) what's wrong, latter tells me there bug in software (i consider such).


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -