Package: less Version: 668-1 Severity: wishlist Tags: patch Dear Maintainer,
lesspipe handles .doc (catdoc) and .pdf (pdftotext), but .docx and OpenDocument files currently fall through to the raw zip. The attached patch adds: *.docx -> docx2txt (package docx2txt) *.odt, *.ods, *.odp -> odt2txt (package odt2txt) It follows the existing pattern: the converter is used when installed, otherwise a one-line "No ... available" message is shown. lesspipe.1 lists the new extensions. Two details: - docx2txt 1.4 runs unzip through a shell with the filename inside double quotes, so passing a hostile name such as 'x"; touch PWNED; ".docx' directly executes the embedded command (verified). The patch instead hands docx2txt a symlink with a fixed name inside a mktemp -d directory, and passes '-' so the text goes to stdout rather than to an infile.txt created next to the viewed file. A docx2txt failure is reported instead of showing nothing. - odt2txt is given --width=-1 so lines are not re-wrapped at 65 columns. Tested with docx2txt 1.4-5 and odt2txt 0.5-7build1, in both lesspipe and lessfile modes and through less via LESSOPEN/LESSCLOSE: a real .docx (output byte-identical to running docx2txt directly), synthetic .odt/.ods/.odp files, uppercase extensions, names containing spaces, quotes and a leading '-', and a corrupt .docx. The patch is git format-patch output against master on salsa and applies with git am. -- System Information: Debian Release: trixie/sid APT prefers noble-updates APT policy: (500, 'noble-updates'), (500, 'noble-security'), (500, 'noble'), (100, 'noble-backports') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 7.0.0-42-generic (SMP w/8 CPU threads; PREEMPT) Kernel taint flags: TAINT_USER Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled
>From 817dd96dfc60ffda9c0e8aa4eb49d58371a794a7 Mon Sep 17 00:00:00 2001 From: CyberKoyo <[email protected]> Date: Mon, 2 Nov 2026 00:41:35 -0500 Subject: [PATCH] lesspipe: add .docx and OpenDocument (.odt/.ods/.odp) support Use docx2txt and odt2txt when installed, following the existing catdoc/pdftotext pattern. docx2txt 1.4 runs unzip through a shell with the filename inside double quotes, so a name containing $(...) or backticks would be executed. Hand it a symlink with a fixed name in a mktemp -d directory instead. It is given '-' so it writes to stdout rather than creating infile.txt next to the viewed file, and a failure is reported instead of showing nothing. odt2txt is given --width=-1 so lines are not re-wrapped at 65 columns. --- debian/lesspipe | 16 ++++++++++++++++ debian/lesspipe.1 | 2 ++ 2 files changed, 18 insertions(+) diff --git a/debian/lesspipe b/debian/lesspipe index 57ef4f1..e64358d 100644 --- a/debian/lesspipe +++ b/debian/lesspipe @@ -127,6 +127,18 @@ if [ $# -eq 1 ] ; then fi ;; + *.docx) + if [ -x "`which docx2txt`" ]; then + # docx2txt passes the filename to a shell, so give it a fixed safe one + d=$(mktemp -d) && ln -s "$(readlink -f -- "$1")" "$d/f.docx" || exit + docx2txt "$d/f.docx" -; rc=$? + rm -rf "$d" + [ $rc -eq 0 ] || echo "docx2txt failed on $1" + else + echo "No docx2txt available" + fi + ;; + *.egg) if [ -x "`which unzip`" ]; then unzip -p "$1" EGG-INFO/PKG-INFO | \ @@ -196,6 +208,10 @@ if [ $# -eq 1 ] ; then fi ;; + *.odt|*.ods|*.odp) + if [ -x "`which odt2txt`" ]; then odt2txt --width=-1 "$1" + else echo "No odt2txt available"; fi ;; + *.pdf) if [ -x "`which pdftotext`" ]; then pdftotext -layout "$1" - else echo "No pdftotext available"; fi ;; diff --git a/debian/lesspipe.1 b/debian/lesspipe.1 index 8e842ef..6142b71 100644 --- a/debian/lesspipe.1 +++ b/debian/lesspipe.1 @@ -68,6 +68,7 @@ This is a list of currently supported extensions *.bz2 *.deb, *.udeb, *.ddeb *.doc + *.docx *.egg *.gif, *.jpeg, *.jpg, *.pcd, *.png, *.tga, *.tiff, *.tif *.iso, *.raw, *.bin @@ -75,6 +76,7 @@ This is a list of currently supported extensions *.tar.lz, *.tlz *.lz *.7z + *.odt, *.ods, *.odp *.pdf *.rar, *.r[0-9][0-9] *.rpm -- 2.43.0

