[Scummvm-cvs-logs] CVS: tools extract.c,1.35,1.36 queenrebuild.c,1.6,1.7 simon2mp3.c,1.24,1.25 util.c,1.3,1.4 util.h,1.5,1.6
Max Horn
fingolfin at users.sourceforge.net
Mon Nov 10 13:42:07 CET 2003
Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv24137
Modified Files:
extract.c queenrebuild.c simon2mp3.c util.c util.h
Log Message:
cleanup; fixed a buffer overflow bug in simon2mp3
Index: extract.c
===================================================================
RCS file: /cvsroot/scummvm/tools/extract.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- extract.c 9 Nov 2003 23:52:39 -0000 1.35
+++ extract.c 10 Nov 2003 21:41:05 -0000 1.36
@@ -102,7 +102,7 @@
uint32 tags;
/* The VCTL header */
- readString(4, buf, input);
+ fread(buf, 1, 4, input);
while (memcmp(buf, "VCTL", 4)) {
pos++;
append_byte(4, buf);
@@ -120,11 +120,11 @@
tags--;
}
- readString(8, buf, input);
+ fread(buf, 1, 8, input);
if (!memcmp(buf, "Creative", 8)) {
- readString(18, buf, input);
+ fseek(input, 18, SEEK_CUR);
} else if (!memcmp(buf, "VTLK", 4)) {
- readString(26, buf, input);
+ fseek(input, 26, SEEK_CUR);
} else {
error("Unexpected data encountered");
}
@@ -213,7 +213,7 @@
}
/* Get the 'SOU ....' header */
- readString(8, buf, input);
+ fread(buf, 1, 8, input);
if (strncmp(buf, f_hdr, 8)) {
printf("Bad SOU\n");
exit(-1);
Index: queenrebuild.c
===================================================================
RCS file: /cvsroot/scummvm/tools/queenrebuild.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- queenrebuild.c 10 Nov 2003 12:38:37 -0000 1.6
+++ queenrebuild.c 10 Nov 2003 21:41:05 -0000 1.7
@@ -228,9 +228,9 @@
checkOpen(inputTbl, INPUT_TBL);
size = fileSize(inputData);
- readString(4, tmp, inputTbl);
+ fread(tmp, 1, 4, inputTbl);
tmp[4] = '\0';
- if (strcmp(tmp, "QTBL")) {
+ if (memcmp(tmp, "QTBL", 4)) {
printf("Invalid TBL file!\n");
exit(-1);
}
@@ -256,7 +256,7 @@
prevOffset = ftell(outputData);
/* Read entry */
- readString(12, entry.filename, inputTbl);
+ fread(entry.filename, 1, 12, inputTbl);
entry.filename[12] = '\0';
entry.bundle = readByte(inputTbl);
entry.offset = readUint32BE(inputTbl);
Index: simon2mp3.c
===================================================================
RCS file: /cvsroot/scummvm/tools/simon2mp3.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- simon2mp3.c 9 Nov 2003 23:52:39 -0000 1.24
+++ simon2mp3.c 10 Nov 2003 21:41:05 -0000 1.25
@@ -21,11 +21,7 @@
#include "extract.h"
-unsigned int filenums[32768];
-unsigned int offsets[32768];
-
char infile_base[256];
-char buf[256];
void end(void)
{
@@ -42,7 +38,7 @@
sprintf(tmp, "%sidx", infile_base);
input = fopen(tmp, "rb");
- while ((size = fread(buf, 1, 2048, input)) > 0) {
+ while ((size = fread(fbuf, 1, 2048, input)) > 0) {
fwrite(fbuf, 1, size, output_idx);
}
fclose(input);
@@ -66,14 +62,16 @@
exit(0);
}
-int get_offsets(void)
+
+int get_offsets(uint32 filenums[], uint32 offsets[])
{
int i;
+ char buf[8];
for (i = 0;; i++) {
- readString(8, buf, input);
+ fread(buf, 1, 8, input);
if (!memcmp(buf, "Creative", 8) || !memcmp(buf, "RIFF", 4)) {
- return(i);
+ return i;
}
fseek(input, -8, SEEK_CUR);
@@ -81,7 +79,7 @@
}
}
-int get_offsets_mac(void)
+int get_offsets_mac(uint32 filenums[], uint32 offsets[])
{
int i, size;
fseek(input, 0, SEEK_END);
@@ -96,26 +94,27 @@
}
-unsigned int get_sound(int sound)
+uint32 get_sound(uint32 offset)
{
FILE *f;
uint32 tot_size;
char outname[256];
int size;
char fbuf[2048];
+ char buf[8];
- fseek(input, offsets[sound], SEEK_SET);
+ fseek(input, offset, SEEK_SET);
- readString(8, buf, input);
+ fread(buf, 1, 8, input);
if (!memcmp(buf, "Creative", 8)) {
- printf("VOC found (pos = %d) :\n", offsets[sound]);
- readString(18, buf, input);
+ printf("VOC found (pos = %d) :\n", offset);
+ fseek(input, 18, SEEK_CUR);
get_voc();
} else if (!memcmp(buf, "RIFF", 4)) {
- printf("WAV found (pos = %d) :\n", offsets[sound]);
+ printf("WAV found (pos = %d) :\n", offset);
get_wav();
} else {
- error("Unexpected data at offset: %i", offsets[sound]);
+ error("Unexpected data at offset: %i", offset);
}
/* Append the converted data to the master output file */
@@ -168,6 +167,8 @@
{
int i, n, size, num;
char tmp[256];
+ uint32 filenums[32768];
+ uint32 offsets[32768];
memccpy(infile_base, infile, '.', strlen(infile));
n = strlen(infile_base);
@@ -190,7 +191,7 @@
sprintf(tmp, "%sdat", infile_base);
output_snd = fopen(tmp, "wb");
- num = get_offsets();
+ num = get_offsets(filenums, offsets);
if (!num) {
printf("This does not seem to be a valid file\n");
@@ -207,7 +208,7 @@
continue;
}
- size += get_sound(i);
+ size += get_sound(offsets[i]);
if (i < num - 1)
writeUint32BE(input, size);
}
@@ -217,6 +218,9 @@
{
int i, size, num;
char tmp[256];
+ uint32 filenums[32768];
+ uint32 offsets[32768];
+
sprintf(infile_base, "simon2.");
@@ -232,7 +236,7 @@
sprintf(tmp, "%sdat", infile_base);
output_snd = fopen(tmp, "wb");
- num = get_offsets_mac();
+ num = get_offsets_mac(filenums, offsets);
if (!num) {
printf("This does not seem to be a valid file\n");
@@ -256,7 +260,7 @@
input = fopen(tmp, "rb");
}
- size += get_sound(i);
+ size += get_sound(offsets[i]);
if (i < num - 1)
writeUint32BE(input, size);
}
Index: util.c
===================================================================
RCS file: /cvsroot/scummvm/tools/util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- util.c 10 Nov 2003 00:08:56 -0000 1.3
+++ util.c 10 Nov 2003 21:41:05 -0000 1.4
@@ -75,11 +75,6 @@
return ret;
}
-void readString(uint32 size, char *dest, FILE *fp) {
- fread(dest, 1, size, fp);
- dest[size+1] = '\0';
-}
-
void writeByte(FILE *fp, uint8 b) {
fwrite(&b, 1, 1, fp);
}
Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/tools/util.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- util.h 9 Nov 2003 23:45:44 -0000 1.5
+++ util.h 10 Nov 2003 21:41:05 -0000 1.6
@@ -97,7 +97,6 @@
uint16 readUint16BE(FILE *fp);
uint32 readUint32BE(FILE *fp);
uint32 readUint32LE(FILE *fp);
-void readString(uint32 size, char *dest, FILE *fp);
void writeByte(FILE *fp, uint8 b);
void writeUint16BE(FILE *fp, uint16 value);
void writeUint32BE(FILE *fp, uint32 value);
More information about the Scummvm-git-logs
mailing list