sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.59k stars 1.25k forks source link

bat throwing error when attempting to open files inside a git repository #2317

Closed eugeneromero closed 9 months ago

eugeneromero commented 2 years ago

Since the latest update in Ubuntu 20.04, from about one month ago, bat (or batcat as it is named in my system) throws an error when trying to open some files. From some light testing, it seems that the files it chokes on are files living inside a git repo. Copying a non-working file outside the git repo, allows bat to open it successfully.

What steps will reproduce the bug?

  1. Go into a folder containing files tracked by git (git status should return something)
  2. run batcat ANYFILE

What happens? batcat throws an error:

$ batcat Dockerfile 
thread 'main' panicked at 'attempted to zero-initialize type `libgit2_sys::git_diff_options`, which is invalid', /usr/share/cargo/registry/bat-0.12.1/debian/cargo_registry/git2-0.8.0/src/diff.rs:451:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Setting the envvar as suggested:

$ batcat Dockerfile
thread 'main' panicked at 'attempted to zero-initialize type `libgit2_sys::git_diff_options`, which is invalid', /usr/share/cargo/registry/bat-0.12.1/debian/cargo_registry/git2-0.8.0/src/diff.rs:451:27
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Setting the new envvar:

$ batcat Dockerfile 
thread 'main' panicked at 'attempted to zero-initialize type `libgit2_sys::git_diff_options`, which is invalid', /usr/share/cargo/registry/bat-0.12.1/debian/cargo_registry/git2-0.8.0/src/diff.rs:451:27
stack backtrace:
   0:     0x55b9350c67c6 - <unknown>
   1:     0x55b9350f65dc - <unknown>
   2:     0x55b9350b79d5 - <unknown>
   3:     0x55b9350bff51 - <unknown>
   4:     0x55b9350bfb51 - <unknown>
   5:     0x55b9350c04a1 - <unknown>
   6:     0x55b9350c6f82 - <unknown>
   7:     0x55b9350c68f4 - <unknown>
   8:     0x55b9350c0032 - <unknown>
   9:     0x55b934f11491 - <unknown>
  10:     0x55b934f113dd - <unknown>
  11:     0x55b934ff9a8b - <unknown>
  12:     0x55b934f60855 - <unknown>
  13:     0x55b934f22736 - <unknown>
  14:     0x55b934f37403 - <unknown>
  15:     0x55b934f387fa - <unknown>
  16:     0x55b934f3c963 - <unknown>
  17:     0x55b934f5cf49 - <unknown>
  18:     0x55b9350b5e31 - <unknown>
  19:     0x55b934f3cbe8 - <unknown>
  20:     0x7f5138c02083 - __libc_start_main
                               at /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
  21:     0x55b934f11bee - <unknown>
  22:                0x0 - <unknown>

What did you expect to happen instead? batcat should display the file as usual.

How did you install bat?

Installed it by means of the official apt package in Ubuntu 20.04. It seems that 0.12.1 is the latest version here, and was updated on August 18, 2022, according to the changelog.


bat version and environment system

$ uname -srm Linux 5.4.0-125-generic x86_64

$ lsb_release -a No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal

bat

$ batcat --version bat 0.12.1

$ env

bat_config

bat_wrapper

No wrapper script for 'bat'.

No wrapper script for 'batcat'.

bat_wrapper_function

No wrapper function for 'bat'.

$ /bin/bash --login -i -c type cat

cat is aliased to `batcat'

No wrapper function for 'batcat'.

tool

$ less --version less 551 (GNU regular expressions)

alombarte commented 2 years ago

Hi,

Thanks for this excellent software. I have used bat as an aliased replacement of cat for about a year with no issues, and I do "batcats" on a daily basis on git repos. Let me contribute with a small comment :)

I started seeing the error today. I have NOT upgraded my Ubuntu distribution, but is certainly a change in the libraries what causes the problem. I installed a couple of terminal applications (Tilix and Kitty) to replace my old Terminator and the bug happened right after that. By looking at their dependencies and the backtrace it looks that the glibc version changed as part of these installations, and bat stopped working.

My Ubuntu has the latest package available bat v0.12.1.

The problem is gone now but it was easily reproducible:

$ cd mkdir -p boom/.git
$ cd boom/.git 
$ touch README.md
# ALL GOOD
$ batcat README.md         
───────┬────────────────────────────────────────────────────────────────────────
       │ File: README.md   <EMPTY>
───────┴────────────────────────────────────────────────────────────────────────
$ git init
Initialized empty Git repository in /tmp/boom/.git/.git/
$ batcat README.md
thread 'main' panicked at 'attempted to zero-initialize type `libgit2_sys::git_diff_options`, which is invalid', /usr/share/cargo/registry/bat-0.12.1/debian/cargo_registry/git2-0.8.0/src/diff.rs:451:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The full backtrace points the libc.

RUST_BACKTRACE=full cat README.md
thread 'main' panicked at 'attempted to zero-initialize type `libgit2_sys::git_diff_options`, which is invalid', /usr/share/cargo/registry/bat-0.12.1/debian/cargo_registry/git2-0.8.0/src/diff.rs:451:27
stack backtrace:
  ...
  20:     0x7feeb6175083 - __libc_start_main
                               at /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
  21:     0x561c42198bee - <unknown>
  22:                0x0 - <unknown>

Yes, this library was affected during the software install.

To solve the problem, I simply removed bat with apt remove bat and downloaded from the releases tab bat_0.22.1_amd64.deb and installed it.

We are back on track now.

eugeneromero commented 2 years ago

Thank you for your comment @alombarte! I can indeed confirm that the latest version available here fixes the issue. In my case I did not even remove the old version with apt remove, I simply installed the new one which automatically replaced the old. I also had to update the old alias, as in these new versions the executable is now called bat as opposed to batcat.

I will however leave the bug report open and wait on the developers to decide what they want to do with it, since it is an issue on the latest official version of a still supported Ubuntu LTS release.

americanhanko commented 2 years ago

@alombarte Do you have unattended-upgrade configured? For me, it looks like an update happened yesterday. From /var/log/apt/history.log, I see:

Start-Date: 2022-09-15  06:35:24
Commandline: /usr/bin/unattended-upgrade
Upgrade: bat:amd64 (0.12.1-1build1, 0.12.1-1ubuntu0.1)
End-Date: 2022-09-15  06:35:24

I'm curious why the latest available version for Ubuntu 20.04 is 0.12.1, when the latest release (0.22.1) from the repository has no (apparent) issues running on Ubuntu 20.04. That being said, the documentation for installation via Ubuntu/apt does indicate that the release may not be the latest, and one can install the latest via dpkg.

sharkdp commented 2 years ago

Thank you for reporting this. I still don't fully understand where this came from? Did Ubuntu publish an update to the bat package that broke things? If so, shouldn't this be reported on the Ubuntu issue tracker?

eugeneromero commented 2 years ago

Hey @sharkdp, thanks for getting back to us on this. I am not sure what the process is for a package to end up in the Ubuntu repos. Therefore, here seemed like the most logical place to report this issue. Should this be notified somewhere else?

sharkdp commented 2 years ago

Maybe @paride could help out here (only if interested of course)?

igorcafe commented 2 years ago

For me, I can reproduce by:

cargo uninstall bat
cargo install bat
$ bat --version
bat 0.22.1

$ cargo --version                 
cargo 1.61.0 (a028ae4 2022-04-29)
paride commented 2 years ago

This is an Ubuntu specific bug caused by a security upload to Focal (src:rust-bat 0.12.1-1ubuntu0.1). I filed a bug for the Ubuntu package on Launchpad, and tagged it regression-update (per [1]):

https://bugs.launchpad.net/ubuntu/+source/rust-bat/+bug/1995868

I tried downgrading to 0.12.1-1build1 and that version works.

Cc: @litios

[1] https://wiki.ubuntu.com/StableReleaseUpdates

litios commented 2 years ago

@paride thanks for the heads up. I'll update it here when the solution is released.

litios commented 2 years ago

A new version has been released to address this issue, 0.12.1-1ubuntu0.2.

The issue was tracked down to the git2 dependency due to an incompatibility with the current rustc available in focal and fixes have been released for all affected packages.