Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghidra cannot handle object files with more than 32k sections #7913

Open
Lehona opened this issue Mar 15, 2025 · 1 comment
Open

Ghidra cannot handle object files with more than 32k sections #7913

Lehona opened this issue Mar 15, 2025 · 1 comment

Comments

@Lehona
Copy link

Lehona commented Mar 15, 2025

Describe the bug
When importing an (object) file with many sections, the import crashes with the following exception:

ERROR REPORT: Unique space id must be between 0 and 32767 inclusive (HeadlessAnalyzer) java.lang.IllegalArgumentException: Unique space id must be between 0 and 32767 inclusive
	at ghidra.program.model.address.AbstractAddressSpace.<init>(AbstractAddressSpace.java:70)
	at ghidra.program.model.address.OverlayAddressSpace.<init>(OverlayAddressSpace.java:36)
	at ghidra.program.database.ProgramOverlayAddressSpace.<init>(ProgramOverlayAddressSpace.java:45)
	at ghidra.program.database.ProgramAddressFactory.addOverlaySpace(ProgramAddressFactory.java:180)
	at ghidra.program.database.OverlaySpaceDBAdapterV1.createOverlaySpace(OverlaySpaceDBAdapterV1.java:89)
	at ghidra.program.database.ProgramDB.createOverlaySpace(ProgramDB.java:1205)
	at ghidra.program.database.mem.MemoryMapDB.createUniqueOverlaySpace(MemoryMapDB.java:662)
	at ghidra.program.database.mem.MemoryMapDB.createOverlaySpace(MemoryMapDB.java:636)
	at ghidra.program.database.mem.MemoryMapDB.createInitializedBlock(MemoryMapDB.java:752)
	at ghidra.app.util.MemoryBlockUtils.createInitializedBlock(MemoryBlockUtils.java:227)
	at ghidra.app.util.opinion.ElfProgramBuilder.createInitializedBlock(ElfProgramBuilder.java:3727)
	at ghidra.app.util.opinion.MemorySectionResolver.processSectionRanges(MemorySectionResolver.java:391)
	at ghidra.app.util.opinion.MemorySectionResolver.resolveSectionMemory(MemorySectionResolver.java:310)
	at ghidra.app.util.opinion.MemorySectionResolver.resolve(MemorySectionResolver.java:286)
	at ghidra.app.util.opinion.ElfProgramBuilder.load(ElfProgramBuilder.java:140)
	at ghidra.app.util.opinion.ElfProgramBuilder.loadElf(ElfProgramBuilder.java:111)
	at ghidra.app.util.opinion.ElfLoader.load(ElfLoader.java:147)
	at ghidra.app.util.opinion.AbstractLibrarySupportLoader.doLoad(AbstractLibrarySupportLoader.java:864)
	at ghidra.app.util.opinion.AbstractLibrarySupportLoader.loadProgram(AbstractLibrarySupportLoader.java:107)
	at ghidra.app.util.opinion.AbstractProgramLoader.load(AbstractProgramLoader.java:129)
	at ghidra.app.util.importer.AutoImporter.importFresh(AutoImporter.java:723)
	at ghidra.app.util.importer.AutoImporter.importFresh(AutoImporter.java:633)
	at ghidra.app.util.importer.AutoImporter.importByLookingForLcs(AutoImporter.java:342)
	at ghidra.app.util.headless.HeadlessAnalyzer.loadPrograms(HeadlessAnalyzer.java:1658)
	at ghidra.app.util.headless.HeadlessAnalyzer.processFileWithImport(HeadlessAnalyzer.java:1538)
	at ghidra.app.util.headless.HeadlessAnalyzer.processWithLoader(HeadlessAnalyzer.java:1745)
	at ghidra.app.util.headless.HeadlessAnalyzer.processWithImport(HeadlessAnalyzer.java:1686)
	at ghidra.app.util.headless.HeadlessAnalyzer.processWithImport(HeadlessAnalyzer.java:1770)
	at ghidra.app.util.headless.HeadlessAnalyzer.processLocal(HeadlessAnalyzer.java:457)
	at ghidra.app.util.headless.AnalyzeHeadless.launch(AnalyzeHeadless.java:198)
	at ghidra.GhidraLauncher.launch(GhidraLauncher.java:81)
	at ghidra.Ghidra.main(Ghidra.java:54)

To Reproduce
Unfortunately I cannot share the binary in question, but any file with enough sections should exhibit this behaviour. This comes up somewhat-commonly when compilers produce function-sections (i.e. one section per function).

Expected behavior
There's no reason for this limitation, so Ghidra should be able to load the file normally.

Environment (please complete the following information):

  • OS: Manjaro
  • Java Version: 21
  • Ghidra Version: 11.3.1
  • Ghidra Origin: Locally built, but no modifications related to this at all.
@Lehona
Copy link
Author

Lehona commented Mar 15, 2025

I did some more digging and maybe it's not the text sections that cause this, but all the other, non-loaded sections. They are all thrown into the address space "other" and thus have to be distinguished by the unique space id, which is limited to 30k. There's around 90k sections total and roughly a 8:1 ratio of non-loaded to loaded sections, so loaded sections alone should not hit the limit (if they use this sort of space id at all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant