libretro / RetroArch

Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.
http://www.libretro.com
GNU General Public License v3.0
10.31k stars 1.84k forks source link

AddressSanitizer + CHD cause hard crash when Cheevos are enabled #9871

Closed negativeExponent closed 4 years ago

negativeExponent commented 4 years ago

First and foremost consider this:

Description

Cheevos enabled causes hard crash when RetroArch and related core is compiled with -fsanitizer when running CHD disks.

Expected behavior

no crash at least.

Actual behavior

as stated in the Descriptions, when cheevos is enabled this can cause crash. Disabling cheevos runs normally.

Steps to reproduce the bug

preparation:

  1. run RA
  2. enable RetroAchievements
  3. load CHD file using any core stated above that has been compiled with -fsanitze
  4. this should crash.

log: https://hastebin.com/isohikudut.sql

Bisect Results

[Try to bisect and tell us when this started happening]

Version/Commit

You can find this information under Information/System Information

Environment information

Jamiras commented 4 years ago

As best as I can tell from the attached log, the problem is in libchdr, which just happens to be getting called via the cheevos code to identify the game:

There's a lot of alignment warnings, then a heap-use-after-free error.

The read stack is through line 241 of libchdr_lzma, the use stack is through line 242: https://github.com/libretro/RetroArch/blob/a88e6f4e1f7342af83bff3182f9b29ed0fb4b6ea/libretro-common/formats/libchdr/libchdr_lzma.c#L241-L242

Maybe swapping the order will fix the problem?

It looks like that error is causing the AddressSanitizer to abort, which appears as the crash.

negativeExponent commented 4 years ago

@Jamiras Thanks for that fast reply. Swapped both lzma_allocator_free && LzmaDec_Free as suggested fixed the abort problem.