Bug 29483 - abort at i386-dis.c:9289
Summary: abort at i386-dis.c:9289
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.40 (HEAD)
: P2 normal
Target Milestone: 2.40
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-13 10:39 UTC by Alan Modra
Modified: 2022-09-12 06:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2022-08-13 10:39:36 UTC
cat > xxx.s <<EOF
 .text
 .byte	0x65,0x62,0x62,0x7d,0x97,0xa0,0x94,0xff,0x20,0x20,0x20,0xae
EOF
gas/as-new -o xxx.o xxx.s
binutils/objdump -d xxx.o

The abort is this one:

  if ((size_t) res >= sizeof (staging_area))
    abort ();

Doubling the buffer size fixes this particular test case.
Comment 1 cvs-commit@gcc.gnu.org 2022-08-16 16:41:11 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9096fc28c62741bfb7962eb5dfdee28a7b1d1345

commit 9096fc28c62741bfb7962eb5dfdee28a7b1d1345
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Aug 16 08:25:49 2022 -0700

    i386: Add MAX_OPERAND_BUFFER_SIZE
    
    When displaying operands, invalid opcodes may overflow operand buffer
    due to additional styling characters.  Each style is encoded with 3
    bytes.  Define MAX_OPERAND_BUFFER_SIZE for operand buffer size and
    increase it from 100 bytes to 128 bytes to accommodate 9 sets of styles
    in an operand.
    
    gas/
    
            PR binutils/29483
            * testsuite/gas/i386/i386.exp: Run pr29483.
            * testsuite/gas/i386/pr29483.d: New file.
            * testsuite/gas/i386/pr29483.s: Likewise.
    
    opcodes/
    
            PR binutils/29483
            * i386-dis.c (MAX_OPERAND_BUFFER_SIZE): New.
            (obuf): Replace 100 with MAX_OPERAND_BUFFER_SIZE.
            (staging_area): Likewise.
            (op_out): Likewise.
Comment 2 H.J. Lu 2022-08-16 16:41:45 UTC
Fixed for 2.40.
Comment 3 cvs-commit@gcc.gnu.org 2022-09-12 06:20:07 UTC
The master branch has been updated by Jan Beulich <jbeulich@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ac3fe48fd61a92d03c66152038df4fc184bf5fcd

commit ac3fe48fd61a92d03c66152038df4fc184bf5fcd
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Sep 12 08:19:55 2022 +0200

    x86: avoid i386_dis_printf()'s staging area for a fair part of output
    
    While PR binutils/29483 has now been addressed differently, this
    originally proposed change still has its merits: Avoiding vsnprintf()
    for typically far more than half of the overall output results in a 2-3%
    performance gain in my testing (with debug builds of objdump, libbfd,
    and libopcodes).
    
    With that part of output no longer using staging_area[], the array also
    doesn't need to be quite as large anymore (the largest presently used
    size is 27, from "64-bit address is disabled").
    
    While limiting the scope of "res" it became apparent that
    - no caller cares about the function's return value,
    - the comment about the return value was wrong,
    - a particular positive return value would have been meaningless to the
      caller.
    Therefore convert the function to return "void" at the same time.