On Mon, Jan 30, 2023 at 02:26:12PM -0600, Eric Blake wrote:
> On Sat, Jan 28, 2023 at 10:31:04PM +0100, Juan Manuel Guerrero wrote:
> > I do not know if this issue has already been reported, but for all
> > systems that distinguish between binary and text I/O, the file should
> > be read in the same mode than it has been created or it may rise reading
> > issues.  When a "frozen" file is created in produce_frozen_state() this
> > is done using binary mode and that is ok.  But when it later is reloaded,
> > the reading is done without specifying the mode and this defaults to
> > text mode breaking/aborting the reading process.  The patch below fixes
> > the issue but it is only intended as suggestion.  Fix the issue as you
> > like.
> 
> Thanks for the report.  I'm not sure if calling SET_BINARY() is the
> best fix, or if it is better to teach m4_path_search() which files
> must be opened in binary mode (vs. in default mode, where the default
> mode might be text on platforms where text is distinct from binary).
> I'll give it some more thought, but may end up including your patch as
> written if I can't think of anything more elegant.

The only other option would be adding a bool parameter to
m4_path_search asking for binary, where freeze.c would be the only
client passing true.  Still, that feels cleaner to open the file
correctly from the get-go, rather than changing it after the fact.

Patch coming up shortly.

> 
> > +++ b/src/freeze.c
> > @@ -268,6 +268,7 @@ reload_frozen_state (const char *name)
> >    file = m4_path_search (name, NULL);
> >    if (file == NULL)
> >      m4_failure (errno, _("cannot open %s"), name);
> > +  SET_BINARY (fileno (file));
> >    current_file = name;
> > 
> >    allocated[0] = 100;
> > 
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to