Commit e9b34d50 authored by Michael Smith's avatar Michael Smith

Ensure ov_open() succeeds before opening the output file.

This has two benefits: it avoids creating useless zero-length files if the
input is invalid, and prevents data losss (bug #579) if the input and output
filenames are identical and the file unopenable.


svn path=/trunk/vorbis-tools/; revision=8153
parent 7d2cc150
......@@ -201,6 +201,13 @@ static int decode_file(char *infile, char *outfile)
}
}
if(ov_open(in, &vf, NULL, 0) < 0) {
fprintf(stderr, "ERROR: Failed to open input as vorbis\n");
fclose(in);
return 1;
}
if(!outfile) {
#ifdef __BORLANDC__
setmode(fileno(stdout), O_BINARY);
......@@ -217,13 +224,6 @@ static int decode_file(char *infile, char *outfile)
}
}
if(ov_open(in, &vf, NULL, 0) < 0) {
fprintf(stderr, "ERROR: Failed to open input as vorbis\n");
fclose(in);
fclose(out);
return 1;
}
if(ov_seekable(&vf)) {
seekable = 1;
length = ov_pcm_total(&vf, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment