Bug 703092 - mutool: clean: endless loop
Summary: mutool: clean: endless loop
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: apps (show other bugs)
Version: 1.18.0
Hardware: PC Linux
: P4 major
Assignee: MuPDF bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-07 00:21 UTC by Steffen Nurpmeso
Modified: 2020-12-14 12:59 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Nurpmeso 2020-11-07 00:21:22 UTC
Hello!
It is maybe a miscompilation, but i can force a mutool compiled on CRUX-Linux 3.6 (not yet released but nonetheless) to hang endlessly via

 # mutool clean -g -s -l -d -z protokoll-januar1942_barrierefrei.pdf xxx.pdf

I interrupted after five minutes.  (The PDF is ~2.5 MB.)
The PDF file is freely available at

  https://www.ghwk.de/fileadmin/Redaktion/PDF/Konferenz/protokoll-januar1942_barrierefrei.pdf

Ciao!
Comment 1 Steffen Nurpmeso 2020-11-21 23:19:03 UTC
More infos.

#?0|kent:src$ pkginfo -o /usr/bin/mutool
Package  File
mupdf    usr/bin/mutool

#?0|kent:src$ prt-get info mupdf
Name:         mupdf
Path:         /usr/ports/opt
Version:      1.18.0
Release:      1
Description:  Lightweight PDF and XPS viewer
URL:          https://www.mupdf.com/
Maintainer:   Juergen Daubert, jue at crux dot nu
Dependencies: glu,libglvnd,harfbuzz,libjpeg-turbo,xorg-libxi

#?0|kent:src$ cat /usr/ports/opt/mupdf/Pkgfile
# Description: Lightweight PDF and XPS viewer
# URL:         https://www.mupdf.com/
# Maintainer:  Juergen Daubert, jue at crux dot nu
# Depends on:  glu libglvnd harfbuzz libjpeg-turbo xorg-libxi

name=mupdf
version=1.18.0
release=1
source=(https://mupdf.com/downloads/archive/$name-$version-source.tar.xz)

build() {
    cd $name-$version-source

    export USE_SYSTEM_LIBS='yes'

    make install \
        prefix=$PKG/usr \
        mandir=$PKG/usr/share/man \
        XCFLAGS="-fpic -fcommon" \
        USE_SYSTEM_JBIG2DEC='no' \
        USE_SYSTEM_OPENJPEG='no' \
        USE_SYSTEM_GLUT='no' \
        USE_SYSTEM_GUMBO='no'

    ln -s mupdf-gl $PKG/usr/bin/mupdf
    rm -r $PKG/usr/share/doc
}

My CFLAGS in /etc/pkgmk.conf are "-O2 -march=x86-64 -pipe", shall that make system use them.
Happy hacking and a nice weekend i wish.
Comment 2 Tor Andersson 2020-11-23 14:12:23 UTC
The hang only happens with the -s (sanitize content streams) flag.

Using the -c (clean content streams) flag finishes processing.
Comment 3 Tor Andersson 2020-11-23 14:15:45 UTC
It only happens when I don't specify any page ranges. Subsetting (even specifying all pages) allows it to finish processing.

This command hangs:

  mutool clean -s protokoll-januar1942_barrierefrei.pdf out.pdf

This command finishes instantly:

  mutool clean -s protokoll-januar1942_barrierefrei.pdf out.pdf 1-N
Comment 4 Steffen Nurpmeso 2020-11-23 19:49:36 UTC
Thanks for looking into this!
I can confirm everything you say.
(I did not know about -c from reading the manual.)
Ciao from Germany,
Comment 5 Robin Watts 2020-12-14 12:59:26 UTC
Fixed by:

commit 723cf4d9e9ac0bace91a077d853dd8d9a6a49ebb
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Wed Nov 25 16:24:28 2020 +0100

    Bug 703092: Fix logic error in structured text scanning.

    When scanning the MCID string for a matching character when running
    the process filter, in the case where we do not remove the character
    we could get stuck at a space character in the input since we'd not
    progress.

    When we match a character we should either remove or skip it, so make
    that decision more explicit.

    This also fixes another potential bug where when we were removing
    a matching character, str->pos would also be advanced so we would miss
    scanning the next character after it.

Thanks for the report.