Bug 259197 - xzgrep should present a message when fed a non-recognised file format
Summary: xzgrep should present a message when fed a non-recognised file format
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL: https://cgit.freebsd.org/src/tree/con...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-16 03:53 UTC by Graham Perrin
Modified: 2024-04-29 09:00 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Perrin freebsd_committer freebsd_triage 2021-10-16 03:53:35 UTC
% xzgrep harfbuzz /var/log/messages.0.bz2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
% zcat /var/log/messages.0.bz2 | grep -e harfbuzz -e electron
Oct 13 07:41:46 mowa219-gjp4-8570p-freebsd pkg[1984]: electron12 upgraded: 12.0.9_1 -> 12.0.9_2 
Oct 13 07:44:15 mowa219-gjp4-8570p-freebsd pkg[3312]: harfbuzz upgraded: 2.9.1 -> 3.0.0 
Oct 13 07:44:15 mowa219-gjp4-8570p-freebsd pkg[3312]: harfbuzz-icu upgraded: 2.9.1 -> 3.0.0 
% zgrep harfbuzz /var/log/messages.0.bz2         
Oct 13 07:44:15 mowa219-gjp4-8570p-freebsd pkg[3312]: harfbuzz upgraded: 2.9.1 -> 3.0.0 
Oct 13 07:44:15 mowa219-gjp4-8570p-freebsd pkg[3312]: harfbuzz-icu upgraded: 2.9.1 -> 3.0.0 
% xzcat /var/log/messages.0.bz2
xzcat: /var/log/messages.0.bz2: File format not recognized
%
Comment 1 Wolfram Schneider freebsd_committer freebsd_triage 2024-04-29 09:00:14 UTC
I think the problem is that the script xzgrep  calls xz(1) with the -f flag by default.


# create a test file
man tcsh | bzip2 > tcsh.bz2
wc tcsh.bz2
     224    1596   56890 tcsh.bz2

# with the -f flag, xz will return the compressed file if the format is unknown, and show no warnings
xzcat -f tcsh.bz2 | wc
     224    1596   56890

# xzgrep falls back to binary search in bz2 data
/usr/bin/xzgrep -c . tcsh.bz2 ; echo $?
222
0

# without -f flag
xzcat tcsh.bz2 | grep tcsh; echo $?
xzcat: tcsh.bz2: File format not recognized
1