Skip to content

-S can cause heap corruption when viewing some binary files #547

@ScoreUnder

Description

@ScoreUnder

What version

$ git rev-parse HEAD
1ca819b

Reproduction steps

  1. Open a binary file in less (say yes to the warning)
  2. Scroll some way down
  3. Type -S to chop long lines

Sometimes this will cause a crash, reported by valgrind as follows:

==2734909== Invalid write of size 1
==2734909==    at 0x11340D: put_wchar (charset.c:700)
==2734909==    by 0x1183B6: cvt_text (cvt.c:95)
==2734909==    by 0x1286AB: pos_shift (position.c:260)
==2734909==    by 0x1286AB: pos_rehead (position.c:300)
==2734909==    by 0x125B1D: toggle_option (option.c:456)
==2734909==    by 0x116E25: mca_opt_char (command.c:519)
==2734909==    by 0x116E25: mca_char (command.c:668)
==2734909==    by 0x116E25: commands (command.c:1360)
==2734909==    by 0x10E99E: main (main.c:475)
==2734909==  Address 0x57a258c is 0 bytes after a block of size 5,244 alloc'd
==2734909==    at 0x484BC13: calloc (vg_replace_malloc.c:1675)
==2734909==    by 0x10ECE8: ecalloc (main.c:512)
==2734909==    by 0x128693: pos_shift (position.c:259)
==2734909==    by 0x128693: pos_rehead (position.c:300)
==2734909==    by 0x125B1D: toggle_option (option.c:456)
==2734909==    by 0x116E25: mca_opt_char (command.c:519)
==2734909==    by 0x116E25: mca_char (command.c:668)
==2734909==    by 0x116E25: commands (command.c:1360)
==2734909==    by 0x10E99E: main (main.c:475)

I can reproduce this with ./less ./less, scrolling down past the first line that says GNU, then typing -S.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions