1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Mach-O: allow 256 ncmds and 32768 sizeofcmds

https://github.com/upx/upx/issues/642
	modified:   p_mach.cpp
	modified:   stub/src/i386-darwin.macho-upxmain.c
	modified:   stub/src/powerpc-darwin.macho-upxmain.c
This commit is contained in:
John Reiser 2022-12-29 14:02:42 -08:00 committed by Markus F.X.J. Oberhumer
parent e56b748435
commit 01a30752c7
3 changed files with 5 additions and 5 deletions

View File

@ -1515,7 +1515,7 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|| mhdri.filetype != mhdr->filetype)
throwCantUnpack("file header corrupted");
unsigned const ncmds = mhdr->ncmds;
if (!ncmds || 24 < ncmds) { // arbitrary limit
if (!ncmds || 256 < ncmds) { // arbitrary limit
char msg[40]; snprintf(msg, sizeof(msg),
"bad Mach_header.ncmds = %d", ncmds);
throwCantUnpack(msg);
@ -1946,8 +1946,8 @@ bool PackMachBase<T>::canPack()
throwCantPack(buf);
}
if (!sz_mhcmds
|| 16384 < sz_mhcmds) { // somewhat arbitrary, but amd64-darwin.macho-upxmain.c
throwCantPack("16384 < Mach_header.sizeofcmds (or ==0)");
|| 32768 < sz_mhcmds) { // somewhat arbitrary, but *-darwin.macho-upxmain.c
throwCantPack("32768 < Mach_header.sizeofcmds (or ==0)");
}
rawmseg_buf.alloc(sz_mhcmds);
rawmseg = (Mach_segment_command *)(void *)rawmseg_buf;

View File

@ -776,7 +776,7 @@ main(int argc, char *argv[])
break;
}
}
char mhdr[16384];
char mhdr[32768];
uint32_t entry = upx_main((struct l_info const *)payload, paysize,
(Mach_header *)mhdr, sizeof(mhdr),
f_exp, f_unf, (Mach_header **)&argv[-2]);

View File

@ -733,7 +733,7 @@ main(int argc, char *argv[])
break;
}
}
char mhdr[16384];
char mhdr[32768];
uint32_t entry = upx_main((struct l_info const *)payload, paysize,
(Mach_header *)mhdr, sizeof(mhdr),
f_exp, f_unf, (Mach_header **)&argv[-2]);