Skip to content
This repository has been archived by the owner. It is now read-only.

Libc++ is not Implicit Integer Truncation Sanitizer clean #40566

Closed
eugenis opened this issue Feb 1, 2019 · 6 comments
Closed

Libc++ is not Implicit Integer Truncation Sanitizer clean #40566

eugenis opened this issue Feb 1, 2019 · 6 comments
Assignees

Comments

@eugenis
Copy link

@eugenis eugenis commented Feb 1, 2019

Bugzilla Link 40566
Resolution FIXED
Resolved on Feb 07, 2019 10:08
Version unspecified
OS Linux
CC @dwblaikie,@LebedevRI,@mclow

Extended Description

#include

int main() {
std::stringstream ss;
ss.write("\xd1", 1);
}

with -fsanitize=implicit-signed-integer-truncation gives:

include/c++/v1/sstream:561:28: runtime error: implicit conversion from type 'std::__1::basic_stringbuf<char, std::__1::char_traits, std::__1::allocator >::int_type' (aka 'int') of value 209 (32-bit, signed) to type 'std::__1::basic_streambuf<char, std::__1::char_traits >::char_type' (aka 'char') changed the value to -47 (8-bit, signed)

basic_stringbuf::overflow converts an int, which is the result of char -> unsigned char -> int conversion, directly to (signed) char.

@eugenis
Copy link
Author

@eugenis eugenis commented Feb 1, 2019

assigned to @mclow

Loading

@mclow
Copy link

@mclow mclow commented Feb 1, 2019

Sweet! It works! (the integer truncation sanitizer)

Loading

@mclow
Copy link

@mclow mclow commented Feb 1, 2019

What happens if you change line 561 of sstream to be:
from
return this->sputc(__c);
to
return this->sputc(traits_type::to_char_type(__c));
?

Loading

@eugenis
Copy link
Author

@eugenis eugenis commented Feb 1, 2019

traits_type::to_char_type makes the cast explicit, and fixes the runtime error

Loading

@mclow
Copy link

@mclow mclow commented Feb 1, 2019

I fixed some of this in revision 352926. Leaving this bug open while I do more testing

Loading

@mclow
Copy link

@mclow mclow commented Feb 7, 2019

I haven't found any other cases. Closing. Please reopen if you find more.

Loading

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants