[Botan-devel] [PATCH] Use ios::binary on streams that are expected to be binary

Jack Lloyd lloyd at randombit.net
Mon Nov 28 17:36:31 EST 2005


Hi Matthew,

As far as I can recall I didn't have any objections to the patch, more likely
it just got lost in the shuffle. I actually don't recall your original patch
affecting the entropy sources, but those seem non-problematic. I'm still not
entirely sure how I feel about having binary I/O baked into the
DataSink/DataSource, as in some contexts you will want to send textual data
through them. I'll try to come up with some way to accomodate this; it may not
end up being the default behaviour, but at least you'll be able to get it
without having to patch the sources.

I'll give this some thought and run whatever I come up with past you before I
push it out in a release.

-Jack

On Tue, Nov 29, 2005 at 11:25:10AM +1300, Matthew Gregan wrote:
> Hello,
> 
> I submitted this patch a few months back, but didn't hear anything.  I'm not
> sure if that was because it's totally bogus and nobody said anything to save
> me the embarassment, or what... but I'm posting it again to get some
> feedback. :-)
> 
> There are a few places in Botan that read from C++ fstreams and appear to
> assume the stream is binary clean, but don't open the stream explicitly as
> binary.  This patch fixes that issue.
> 
> We've had this patch applied to a local copy of Botan in monotone for a few
> releases now--it solved the problems we ran into, and we haven't seen any
> problematic behaviour caused by it.  If the patch isn't totally bogus, it'd
> be nice to have it applied upstream to reduce the delta between Botan
> releases and what we have in our tree.
> 
> Thanks,
> -mjg
> -- 
> Matthew Gregan                     |/
>                                   /|                kinetik at orcon.net.nz

> diff -BNru Botan-1.4.9/modules/es_ftw/es_ftw.cpp Botan-1.4.9-bin/modules/es_ftw/es_ftw.cpp
> --- Botan-1.4.9/modules/es_ftw/es_ftw.cpp	2005-03-14 13:31:05.000000000 +1300
> +++ Botan-1.4.9-bin/modules/es_ftw/es_ftw.cpp	2005-08-07 18:56:40.000000000 +1200
> @@ -88,7 +88,7 @@
>  *************************************************/
>  void FTW_EntropySource::gather_from_file(const std::string& filename)
>     {
> -   std::ifstream in(filename.c_str());
> +   std::ifstream in(filename.c_str(), std::ios::binary);
>     if(!in) return;
>  
>     SecureVector<byte> read_buf(1024);
> diff -BNru Botan-1.4.9/src/data_snk.cpp Botan-1.4.9-bin/src/data_snk.cpp
> --- Botan-1.4.9/src/data_snk.cpp	2005-03-14 13:31:04.000000000 +1300
> +++ Botan-1.4.9-bin/src/data_snk.cpp	2005-08-07 18:56:40.000000000 +1200
> @@ -32,7 +32,7 @@
>  *************************************************/
>  DataSink_Stream::DataSink_Stream(const std::string& file) : fsname(file)
>     {
> -   sink = new std::ofstream(fsname.c_str());
> +   sink = new std::ofstream(fsname.c_str(), std::ios::binary);
>     if(!sink->good())
>        throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname);
>     owns = true;
> diff -BNru Botan-1.4.9/src/data_src.cpp Botan-1.4.9-bin/src/data_src.cpp
> --- Botan-1.4.9/src/data_src.cpp	2005-03-14 13:31:04.000000000 +1300
> +++ Botan-1.4.9-bin/src/data_src.cpp	2005-08-07 18:56:40.000000000 +1200
> @@ -156,7 +156,7 @@
>  *************************************************/
>  DataSource_Stream::DataSource_Stream(const std::string& file) : fsname(file)
>     {
> -   source = new std::ifstream(fsname.c_str());
> +   source = new std::ifstream(fsname.c_str(), std::ios::binary);
>     if(!source->good())
>        throw Stream_IO_Error("DataSource_Stream: Failure opening " + fsname);
>     total_read = 0;
> diff -BNru Botan-1.4.9/src/es_file.cpp Botan-1.4.9-bin/src/es_file.cpp
> --- Botan-1.4.9/src/es_file.cpp	2005-03-14 13:31:04.000000000 +1300
> +++ Botan-1.4.9-bin/src/es_file.cpp	2005-08-07 18:56:40.000000000 +1200
> @@ -39,7 +39,7 @@
>     u32bit read = 0;
>     for(u32bit j = 0; j != sources.size(); j++)
>        {
> -      std::ifstream random_source(sources[j].c_str());
> +      std::ifstream random_source(sources[j].c_str(), std::ios::binary);
>        if(!random_source) continue;
>        random_source.read((char*)output + read, length);
>        read += random_source.gcount();

> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://www.randombit.net/mailman/listinfo/botan-devel




More information about the botan-devel mailing list