mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-04 03:33:44 +01:00
Nothing here is known to misbehave on a real file - it's the input validation around the fixes in the preceding commits. ElfReader's constructor read e_phoff and e_shoff out of the header to find the segment and section tables, before anything had established there was a header there; LoadInto's size check only runs later. It leaves header null in that case now, and the accessors that use it cope. GetSegmentPtr didn't range-check the segment index at all, and both it and GetSectionDataPtr accepted an offset exactly at the end of the file, which addresses no bytes. GetSectionAddr and GetSectionSize took an index on trust. LoadRelocations2 got most of this commit. Its segment end came from p_filesz without checking the segment fits in the file, so the whole decode could run off the end of the buffer. Within it, the flag and type tables are indexed by bitfields out of each command word and were never checked against the table sizes (which themselves come from the file); the loop only guaranteed one byte was left before reading a two-byte command, and the branches that consume a further two or four bytes checked nothing at all; and the offset segment number - unlike the address segment number a few lines up - was used to index segmentVAddr unchecked, though it's wide enough to exceed it. The command read is byte-wise now too: how far buf has advanced depends on those file-supplied table sizes, so it isn't necessarily even. LoadSymbols only checked that a symbol name started inside the file, not that it was terminated there. Also dropped the atomic counter and the ParallelLoop.h include left over from when LoadRelocations ran in parallel. pspautotests 314/314 with --graphics=software. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9