Fix buffer overflows, null pointer dereferences, and unsafe string ops in libdmg#3
Draft
Fix buffer overflows, null pointer dereferences, and unsafe string ops in libdmg#3
Conversation
…erations Agent-Logs-Url: https://github.com/OpenJailbreak/libdmg/sessions/a42b6b0b-6325-46e0-a158-024af675ea6b Co-authored-by: posixninja <50025+posixninja@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Search for issues in the project
Fix buffer overflows, null pointer dereferences, and unsafe string ops in libdmg
Apr 4, 2026
posixninja
approved these changes
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several memory safety bugs in the DMG parsing and writing paths that could cause crashes on malformed input or buffer overflows on unbounded string operations.
Changes
Buffer overflow (
abstractfile.c)vsprintfinto a fixed 1024-byte stack buffer →vsnprintfwith boundsNULL pointer dereferences
All cases follow the same pattern:
getResourceByKey(...)can return NULL but the result was immediately dereferenced without a check.dmgfile.c—openDmgFile: Gracefully return NULL (with resource cleanup) if"blkx"key is absentresources.c—readNSiz: Return NULL if"nsiz"key is absentresources.c—getDataByID: Added NULL guard on theresourceparameter itselfpartition.c—readApplePartitionMap: ChainedgetResourceByKey+getDataByIDwith no checks on eitherdmglib.c: Three functions (extractDmg,calculateMasterChecksum,convertToISO) all directly dereferencedgetResourceByKeyresultsUnsafe strcpy of caller-supplied string (
partition.c)createApplePartitionMapusedstrcpyto writevolumeTypeinto a fixed 32-bytepmParTypefield:Debug information leak (
partition.c)Removed a leftover
printfinwriteATAPIthat printed the internal malloc address and allocation size of a buffer.Original prompt