Opened 10 years ago
Closed 9 years ago
#8165 closed Bugs (fixed)
basic_text_iprimitive loads garbage instead of throwing
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | serialization archive_exception input_stream_error | Cc: |
Description
Hi,
When loading several objects from a text_iarchive, one can load one too many object without the archive throwing an exception. In such case, the last object loaded will contain garbage. If one tries to load yet another object, then an exception is thrown. Here is a minimal working example to show the issue:
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <iostream> #include <sstream> int main() { std::stringstream ss; { boost::archive::text_oarchive oarchive(ss); char a = 'a', b = 'b'; oarchive << a << b; } std::cout << "saved: \"" << ss.str() << "\"\n"; { boost::archive::text_iarchive iarchive(ss); char a, b, garbage, will_fail; iarchive >> a; std::cout << "happily loaded a:\"" << a << "\"\n"; iarchive >> b; std::cout << "happily loaded b:\"" << b << "\"\n"; iarchive >> garbage; std::cout << "happily loaded garbage:\"" << garbage << "\"\n"; try { iarchive >> will_fail; } catch (std::exception const& e) { std::cout << e.what(); throw; } } }
Attached is a patch that seems to fix the problem (and removes some trailing white spaces from the sources). I also ran all of Boost.Serialization's unit tests with the fix and everything passes.
Regards,
Louis Dionne
Attachments (1)
Change History (5)
by , 10 years ago
Attachment: | basic_text_iprimitive.diff added |
---|
comment:1 by , 10 years ago
By the way, Chrome won't properly display the captcha to validate that you're a human when you upload a patch containing links. This caused some confusion on my side and I accidently double posted. Sorry!
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 9 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Version: | Boost 1.53.0 → Boost Development Trunk |
This problem is not fixed at all.
if(! is.fail()){
is >> t; return;
}
above code is not changed to:
if(is >> t){
return;
}
comment:4 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
OK - I've checked in the change.
Patch for the described issue.