bugGNU Octave - Bugs: bug #51158, save function corrupts text /...


bug #51158: save function corrupts text / binary files when appending as binary / text respectively

Submitted by:  Tasos Papastylianou <tpapastylianou>
Submitted on:  Thu 01 Jun 2017 09:52:19 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Tasos Papastylianou <poacheR> Open/Closed:  Open
Release:  4.2.1 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Sun 04 Jun 2017 03:09:47 PM UTC, comment #2: 

I agree that it would be nicer to have a warning message and stop appending, rather than corrupting the existing data file.

An easy way to check whether the file is an Octave binary data file is to look for the special pattern 'Octave' at the beginning of the file.  In an m-file, something like this would work

fid = fopen (filename, "rb");
sig = fread (fid, 6, "*uchar");
is_binary = strcmp (sig.', "Octave");

I think that may need to be converted to C++.

Rik <rik5>
Project Administrator
Thu 01 Jun 2017 09:54:39 PM UTC, comment #1: 

apologies, the second line in the code slipped through, please ignore.

Tasos Papastylianou <tpapastylianou>
Thu 01 Jun 2017 09:52:19 PM UTC, original submission:  

Consider the following code:

a = 1;
save -text binfile a
save -text textfile a
save -binary binfile a
a = 2;
save -text -append binfile a
save -binary -append textfile a
load textfile a
a                 % -- a =  1
load binfile a    % -- error: load: trouble reading binary file 'binfile'

On linux I could check what kind of file it is before appending, e.g.:

system('file textfile')   % -- textfile: data
system('file binfile')    % -- binfile: Octave binary data (little endian)

but obviously, this is not a portable solution.

Proposal: If save is called with the append option, it should first check that the file type specified is the same as the target, otherwise exit with an error.

Tasos Papastylianou <tpapastylianou>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by tpapastylianou (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-06-04 rik5 Priority5 - Normal => 3 - Low
        StatusNone => Confirmed

    Back to the top

    Powered by Savane 3.6