🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.bugs.dist
1 messages
1 total messages Started by Koyo Keiter Mon, 02 Nov 2026 07:10
Bug#1152840: lesspipe: add .docx and OpenDocument (.odt/.ods/.odp) support
#2958
Author: Koyo Keiter
Date: Mon, 02 Nov 2026 07:10
150 lines
6522 bytes
This is a multi-part MIME message sent by reportbug.


--===============2028045530226529324==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============2028045530226529324==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="0001-lesspipe-add-.docx-and-OpenDocument-.odt-.ods-.odp-s.patch"

From 817dd96dfc60ffda9c0e8aa4eb49d58371a794a7 Mon Sep 17 00:00:00 2001
From: CyberKoyo <koyo.keiter@gmail.com>
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


--===============2028045530226529324==--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads