[Scilab-users] Possible bug in wavread

Federico Miyara fmiyara at fceia.unr.edu.ar
Mon Feb 25 01:06:35 CET 2019


Dear all,

I'm reviewing the wavread function code which I could find (on Windows 
7) at the following path:

C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci

There is a code segment at the beginninig intended to detect if the 
wavfile has or not the .wav extension:

// Append .wav extension if necessary
if ( strindex(wavfile, ".") == [] ) then
wavfile = wavfile + ".wav";
end

This contains a bug, since the wavfile name might contain a dot 
different from the one between the name and the extension. The normal 
case would be

sound.wav

and in this case the code works fine if the trailing .wav is absent. But 
in a case such as

sound_v1.1.wav

the code will detect a dot within the abbreviated name 'sound_v1.1' and 
will not append the .wav extension, hence the function will fail to find 
and open the file.

Fortunately the issue is solved quite easily:

// Append .wav extension if necessary
if (~(max(strindex(wavfile,'.wav')) == length(wavfile)-3)) then
wavfile = wavfile + '.wav';
end

The proposed patch tests whether '.wav' is the last sub-string of the 
file name.

Note: '.wav' might appear more than once or might even appear only once 
but in the middle of the name. In such cases it is not a valid wav 
extension. This case might appear unlikely, but it is a possibility. For 
instance, some educator might present an example called:

'example_of_.wav_file.wav'

Regards,

Federico Miyara





---
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190224/f1024d88/attachment.htm>


More information about the users mailing list