Issues when searching with '-z'

Author: wavexxCreated Nov 6, 2018Updated Jul 2, 2025

I really have some troubles when trying to use ag with '-z' to search inside compressed files. Simple gzip compressed files. I have run into all reported bugs here: segfaults (#1157), random messages (#1243) and inconsistent results due to early exists or plainly wrong hits.

I'm using ag 2.1.0 from Debian unstable.

One example: I'm on /usr/share/doc/ trying to find some documentation and searching through gzipped files with ag -z. I simply cannot use ag: it just stops with "truncated file: Success" somewhere. Generally after printing garbage results.

I've found one example:

$ file changelog.Debian.gz
changelog.Debian.gz: gzip compressed data, max compression, from Unix, original size 16367
$ ag -z test changelog.Debian.gz
168:  * Use a correct way to test thing in shell (Closes: #443715)

197:n
ag: truncated file: Not a directory

wat?? Here's what grep says:

$ zgrep -n test changelog.Debian.gz
168:  * Use a correct way to test thing in shell (Closes: #443715)
196:  * Add a note on what unison-latest-stable is supposed to do in
259:    binary to unison-latest-stable and use this binary in the alternative
343:     - it'd really annoy me if the version in woody wasn't the latest

so, huh, the 197 wasn't "too far" from a real hit..

Sadly, this makes searching through directories with -z simply impossible: ag will stop for random reasons anywhere in the tree. I can provide more details and test samples if needed (almost any gzipped file will do).

$ ag --version
ag version 2.1.0

Features:
  +jit +lzma +zlib

Source: ggreer/the_silver_searcher