Opened 5 months ago

Closed 3 weeks ago

#15179 closed defect (fixed)

AGS: lzwexpand SIGBUS on strict-alignment archs

Reported by: dwatteau Owned by: dwatteau
Priority: normal Component: Engine: AGS
Version: Keywords: strict-alignment, sigbus
Cc: Game:

Description

Testing the current Git HEAD on a mips64el device, which is 64 bits, little-endian, and has strict-alignment constraints.

Running Maniac Mansion Deluxe immediately causes the following SIGBUS, on this device:

Program terminated with signal SIGBUS, Bus error.
#0  AGS3::lzwexpand (src=0x341fc30000 "\300\200\002", src_sz=22433, dst=0x3455f3c000 "\200\002", dst_sz=128008)
    at engines/ags/shared/util/lzw.cpp:225
225                                     jshort = BBOp::Int16FromLE(*(reinterpret_cast<const int16_t *>(src_ptr)));

(gdb) bt
#0  AGS3::lzwexpand (src=0x341fc30000 "\300\200\002", src_sz=22433, dst=0x3455f3c000 "\200\002", dst_sz=128008)
    at engines/ags/shared/util/lzw.cpp:225
#1  0x0000003470d3c81c in AGS3::load_lzw (in=0x341dafb500, dst_bpp=<optimized out>, pal=<optimized out>)
    at engines/ags/shared/util/compress.cpp:408
#2  0x0000003470d1d148 in AGS3::AGS::Shared::ReadMainBlock (room=0x3487c14000, in=0x341dafb500, data_ver=<optimized out>)
    at engines/ags/shared/game/room_file.cpp:299

Full GDB backtrace attached below.

I guess that doing a build with UBsan on a regular x86 desktop should help testing this.

Attachments (1)

gdb-ags-lzwexpand-sigbus-backtrace.txt (19.6 KB ) - added by dwatteau 5 months ago.
full GDB backtrace on the MIPS device with strict-alignment constraints

Download all attachments as: .zip

Change History (4)

by dwatteau, 5 months ago

full GDB backtrace on the MIPS device with strict-alignment constraints

comment:1 by dwatteau, 6 weeks ago

FWIW, this was also caught by UBSan on regular x86:

engines/ags/shared/util/lzw.cpp:225:32: runtime error: load of misaligned address 0x5e50b242f227 for type 'const int16_t', which requires 2 byte alignment
0x5e50b242f227: note: pointer points here
 00 00 c8 00 00  d0 00 d0 ff 00 d0 00 d0  00 d0 00 d0 00 d0 00 d0  00 d0 00 d0 ff 00 d0 00  d0 00 d0
             ^ 

I've just opened Github PR https://github.com/scummvm/scummvm/pull/6185 which fixes the issue with Maniac Mansion Deluxe, here.

comment:2 by dwatteau, 3 weeks ago

In 176430f3:

AGS: Fix lzwexpand on strict-alignment platforms

Fixes TRAC #15179, where starting Maniac Mansion Deluxe on mips64el would
trigger a SIGBUS. Also caught by UBSan.

comment:3 by dwatteau, 3 weeks ago

Owner: set to dwatteau
Resolution: fixed
Status: newclosed

Closing this ticket, as the problem has been fixed with the (upstreamed) PR above.

Note: See TracTickets for help on using tickets.