Skip to content

multibytes characters in file path are not taken into account when wrapping the header, which leads to bat crashing #3230

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

Open
vejkse opened this issue Mar 9, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@vejkse
Copy link

vejkse commented Mar 9, 2025

What steps will reproduce the bug?

  1. Run touch /tmp/A—B가, where ‘—’ is a multibyte UTF-8 character and ’가’ is a multibyte double-width CJK character.
  2. Run bat --terminal-width=30 /tmp/A—B가.

What happens?

bat crashes:

thread 'main' panicked at /usr/src/debug/rust/rustc-1.84.0-src/library/core/src/str/mod.rs:648:21:
byte index 21 is not a char boundary; it is inside '가' (bytes 20..23) of `File: /tmp/A—B가   <EMPTY>`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
───────┬──────────────────────

Different widths give different results:

  • with 26 or 27, it crashes with the boundary inside ‘—’;
  • with 21 or 22, it doesn’t crash but ANSI colour codes are broken: 146;131;116m│ m <EMPTY>.

What did you expect to happen instead?

Depending on the width, either not crashing or not breaking ANSI colour codes.

How did you install bat?

I’m using the latest ArchLinux package.


bat version and environment

Software version

bat 0.25.0 (v0.25.0-modified)

Operating system

Linux 6.13.5-arch1-1

Command-line

bat --diagnostic

Environment variables

BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=truecolor
LANG=en_US.UTF-8
LC_ALL=<not set>
LESS=' --RAW-CONTROL-CHARS --tilde --incsearch --ignore-case --clear-screen '
MANPAGER='nvim +Man'\!''
NO_COLOR=<not set>
PAGER=less
SHELL=/bin/bash
TERM=alacritty
XDG_CACHE_HOME=/home/vejkse/.cache
XDG_CONFIG_HOME=/home/vejkse/.config

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

--theme=gruvbox-dark

Custom assets metadata

Could not read contents of '/home/vejkse/.cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

'/home/vejkse/.cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version
less 668 (PCRE2 regular expressions)
Copyright (C) 1984-2024  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
@donovanglover
Copy link

Had this issue for a while now on NixOS. Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants