fix buffer overflow

This would cause exceptions when encrypting/decrypting CIA files to
`0:/gm9/out`.
This commit is contained in:
ZeroSkill1 2023-03-22 17:55:38 +03:00 committed by d0k3
parent 9514755989
commit 64414e12ab

View File

@ -1317,12 +1317,18 @@ u32 CryptCiaFile(const char* orig, const char* dest, u16 crypto) {
// if not inplace: take over CIA metadata
if (!inplace && (info.size_meta == CIA_META_SIZE)) {
CiaMeta* meta = (CiaMeta*) (void*) (cia + 1);
if ((fvx_qread(orig, meta, info.offset_meta, CIA_META_SIZE, NULL) != FR_OK) ||
(fvx_qwrite(dest, meta, info.offset_meta, CIA_META_SIZE, NULL) != FR_OK)) {
CiaMeta* meta = (CiaMeta*) malloc(sizeof(CiaMeta));
if (!meta) {
free(cia);
return 1;
}
if ((fvx_qread(orig, meta, info.offset_meta, CIA_META_SIZE, NULL) != FR_OK) ||
(fvx_qwrite(dest, meta, info.offset_meta, CIA_META_SIZE, NULL) != FR_OK)) {
free(cia);
free(meta);
return 1;
}
free(meta);
}
// fix TMD hashes, write CIA stub to destination