notaz.gp2x.de
/
pcsx_rearmed.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #563 from gameblabla/remove_junk
[pcsx_rearmed.git]
/
libpcsxcore
/
ppf.c
diff --git
a/libpcsxcore/ppf.c
b/libpcsxcore/ppf.c
index
0d80107
..
a76b153
100644
(file)
--- a/
libpcsxcore/ppf.c
+++ b/
libpcsxcore/ppf.c
@@
-183,7
+183,7
@@
void BuildPPFCache() {
char method, undo = 0, blockcheck = 0;
int dizlen, dizyn;
unsigned char ppfmem[512];
char method, undo = 0, blockcheck = 0;
int dizlen, dizyn;
unsigned char ppfmem[512];
- char szPPF[MAXPATHLEN];
+ char szPPF[MAXPATHLEN
* 2
];
int count, seekpos, pos;
u32 anz; // use 32-bit to avoid stupid overflows
s32 ladr, off, anx;
int count, seekpos, pos;
u32 anz; // use 32-bit to avoid stupid overflows
s32 ladr, off, anx;
@@
-212,7
+212,8
@@
void BuildPPFCache() {
if (ppffile == NULL) return;
memset(buffer, 0, 5);
if (ppffile == NULL) return;
memset(buffer, 0, 5);
- fread(buffer, 3, 1, ppffile);
+ if (fread(buffer, 3, 1, ppffile) != 3)
+ goto fail_io;
if (strcmp(buffer, "PPF") != 0) {
SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF);
if (strcmp(buffer, "PPF") != 0) {
SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF);
@@
-235,12
+236,14
@@
void BuildPPFCache() {
fseek(ppffile, -8, SEEK_END);
memset(buffer, 0, 5);
fseek(ppffile, -8, SEEK_END);
memset(buffer, 0, 5);
- fread(buffer, 4, 1, ppffile);
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
if (strcmp(".DIZ", buffer) != 0) {
dizyn = 0;
} else {
if (strcmp(".DIZ", buffer) != 0) {
dizyn = 0;
} else {
- fread(&dizlen, 4, 1, ppffile);
+ if (fread(&dizlen, 4, 1, ppffile) != 4)
+ goto fail_io;
dizlen = SWAP32(dizlen);
dizyn = 1;
}
dizlen = SWAP32(dizlen);
dizyn = 1;
}
@@
-266,12
+269,15
@@
void BuildPPFCache() {
fseek(ppffile, -6, SEEK_END);
memset(buffer, 0, 5);
fseek(ppffile, -6, SEEK_END);
memset(buffer, 0, 5);
- fread(buffer, 4, 1, ppffile);
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
dizlen = 0;
if (strcmp(".DIZ", buffer) == 0) {
fseek(ppffile, -2, SEEK_END);
dizlen = 0;
if (strcmp(".DIZ", buffer) == 0) {
fseek(ppffile, -2, SEEK_END);
- fread(&dizlen, 2, 1, ppffile);
+ // TODO: Endian/size unsafe?
+ if (fread(&dizlen, 2, 1, ppffile) != 2)
+ goto fail_io;
dizlen = SWAP32(dizlen);
dizlen += 36;
}
dizlen = SWAP32(dizlen);
dizlen += 36;
}
@@
-298,13
+304,19
@@
void BuildPPFCache() {
// now do the data reading
do {
fseek(ppffile, seekpos, SEEK_SET);
// now do the data reading
do {
fseek(ppffile, seekpos, SEEK_SET);
- fread(&pos, 4, 1, ppffile);
+ if (fread(&pos, sizeof(pos), 1, ppffile) != sizeof(pos))
+ goto fail_io;
pos = SWAP32(pos);
pos = SWAP32(pos);
- if (method == 2) fread(buffer, 4, 1, ppffile); // skip 4 bytes on ppf3 (no int64 support here)
+ if (method == 2) {
+ // skip 4 bytes on ppf3 (no int64 support here)
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
+ }
anz = fgetc(ppffile);
anz = fgetc(ppffile);
- fread(ppfmem, anz, 1, ppffile);
+ if (fread(ppfmem, anz, 1, ppffile) != anz)
+ goto fail_io;
ladr = pos / CD_FRAMESIZE_RAW;
off = pos % CD_FRAMESIZE_RAW;
ladr = pos / CD_FRAMESIZE_RAW;
off = pos % CD_FRAMESIZE_RAW;
@@
-331,6
+343,12
@@
void BuildPPFCache() {
FillPPFCache(); // build address array
SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF);
FillPPFCache(); // build address array
SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF);
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(ppffile);
}
// redump.org SBI files, slightly different handling from PCSX-Reloaded
}
// redump.org SBI files, slightly different handling from PCSX-Reloaded
@@
-347,16
+365,21
@@
int LoadSBI(const char *fname, int sector_count) {
return -1;
sbi_sectors = calloc(1, sector_count / 8);
return -1;
sbi_sectors = calloc(1, sector_count / 8);
- if (sbi_sectors == NULL)
+ if (sbi_sectors == NULL) {
+ fclose(sbihandle);
return -1;
return -1;
+ }
// 4-byte SBI header
// 4-byte SBI header
- fread(buffer, 1, 4, sbihandle);
+ if (fread(buffer, 1, 4, sbihandle) != 4)
+ goto fail_io;
+
while (1) {
s = fread(sbitime, 1, 3, sbihandle);
if (s != 3)
while (1) {
s = fread(sbitime, 1, 3, sbihandle);
if (s != 3)
- break;
- fread(&t, 1, 1, sbihandle);
+ goto fail_io;
+ if (fread(&t, sizeof(t), 1, sbihandle) != sizeof(t))
+ goto fail_io;
switch (t) {
default:
case 1:
switch (t) {
default:
case 1:
@@
-377,8
+400,14
@@
int LoadSBI(const char *fname, int sector_count) {
}
fclose(sbihandle);
}
fclose(sbihandle);
-
return 0;
return 0;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(sbihandle);
+ return -1;
}
void UnloadSBI(void) {
}
void UnloadSBI(void) {