[iostreams] Hang when constructing an xml_iarchive with non-existent source
I have a function that uses a chain of filters that I am using to read encrypted, bzipped data from file. It is working fine. However, I have just discovered that if I call my function with a file that does not exist, the code hangs in the constructor for xml_iarchive. Of course, I have since edited my code to trap non-existent files before the code gets that far, but I am surprised that: * is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source Is this correct behaviour or a bug? Of course, it is the programmer's responsibility to ensure the source exists, but a hang rather than an exception seems suggests to me that something has been overlooked in the library. The (edited) function exhibiting this behaviour is given below. I am using gcc 3.2.3 and Boost 1.33.1. Paul void load(const std::string& filename) { //my revised tests "filename" here and bails out if the file does not exist try { boost::iostreams::filtering_istream in; in.push(boost::iostreams::bzip2_decompressor()); in.push(MyInputEncryptionFilter()); in.push(boost::iostreams::bzip2_decompressor()); in.push(boost::iostreams::file_source(filename, BOOST_IOS::in | BOOST_IOS::binary)); if (!in.is_complete()) { std::cerr << "Error creating filtering input stream" << std::endl; return; } boost::archive::xml_iarchive input_archive(in); //deserialise file here return; } //various catches removed }
Paul Giaccone wrote:
* is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source
Is this correct behaviour or a bug? Of course, it is the programmer's responsibility to ensure the source exists, but a hang rather than an exception seems suggests to me that something has been overlooked in the library.
without more information its hard to know. inside of what function is it hanging? Robert Ramey
Robert Ramey wrote:
Paul Giaccone wrote:
* is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source
Is this correct behaviour or a bug?
without more information its hard to know. inside of what function is it hanging?
The hang is on this line: boost::archive::xml_iarchive input_archive(in); //HANGS The attached complete program, based on the code I posted originally, hangs in the same place in Windows (Visual C++ .NET 7.1.3088). I haven't tested it in Linux (gcc 3.2.3) but the program I was running when I encountered the problem hung in the same place and is more or less the same as the one attached. Note that the attached program deliberately does not check for the existence of the file in order to enforce the observed behaviour. Additional info (although this might not be relevant): Compiler flags: /Od /I "W:\boost\boost_1_33_1\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug/" /Fd"Debug/vc70.pdb" /W4 /nologo /c /Wp64 /ZI /TP Link flags: /OUT:"Debug/IostreamsTest.exe" /INCREMENTAL /NOLOGO /LIBPATH:"W:\boost\boost_1_33_1\lib" /DEBUG /PDB:"Debug/IostreamsTest.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Paul #include <iostream> #include <boost/archive/xml_iarchive.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/device/file.hpp> #include <boost/iostreams/filter/bzip2.hpp> void load(const std::string& filename) { boost::iostreams::filtering_istream in; in.push(boost::iostreams::bzip2_decompressor()); in.push(boost::iostreams::file_source(filename, BOOST_IOS::in | BOOST_IOS::binary)); if (!in.is_complete()) { std::cerr << "Error creating filtering input stream" << std::endl; return; } boost::archive::xml_iarchive input_archive(in); //HANGS if //deserialise file here return; } int main(void) { load("not a file"); //this will make load() hang unless the non-existence of the file is caught }
I wonder if this is bzip-related. If you comment out the bzip line, the program throws an exception: Exception thrown: First-chance exception at 0x7c59bbf3 in IostreamsTest.exe: Microsoft C++ exception: boost::archive::xml_archive_exception @ 0x0012fad0. Breaks at: this->restore() in: ios_flags_saver::~ios_flags_saver() Call stack: KERNEL32.DLL!7c59bbf3() KERNEL32.DLL!7c59bbf3()
IostreamsTest.exe!boost::io::ios_flags_saver::~ios_flags_saver() Line 44 + 0xf C++
IostreamsTest.exe!boost::archive::basic_xml_grammar<char>::my_parse(std::basic_istream<char,std::char_traits<char>
& is={...}, const boost::spirit::rule<boost::spirit::scanner<std::basic_string<char,std::char_traits<char>,std::allocator<char> ::iterator,boost::spirit::scanner_policies<boost::spirit::iteration_policy,boost::spirit::match_policy,boost::spirit::action_policy> ,boost::spirit::nil_t,boost::spirit::nil_t> & rule_={...}, char delimiter='t') Line 176 + 0x20 C++
Paul Giaccone wrote:
Robert Ramey wrote:
Paul Giaccone wrote:
* is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source
Is this correct behaviour or a bug?
participants (2)
-
Paul Giaccone
-
Robert Ramey