LibreSign / LibreSign/libresign

[Dependency] smalot/pdfparser: Font::getDetails() throws TypeError for PDFs with indirect /Encoding objects (upstream fix available in #822/#823)

Open
#7,706 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
818
Forks
146
Avg merge
11h 31m
Merged PRs (30d)
326

Description

Bug Report

Note: This is not a bug in LibreSign itself, but a heads-up about a bug in a vendored dependency that affects LibreSign users.

Summary

When uploading certain PDF files (e.g. PDFs with Type1 fonts where is an indirect object reference), LibreSign throws a fatal error:

This originates in the vendored library at:

Root Cause

The PDF spec (Table 5.11) allows a font's entry to be either a name or an indirect reference to an encoding dictionary (). When it is an indirect reference, tried to cast the to string via , which throws a in PHP 8+ because has no .

The affected PDF is not corrupt — it is valid per the PDF specification.

Upstream Fix

This has been reported and fixed upstream in :

The fix adds a type-safe branch in that handles encoding dictionaries by reading the header entry instead of casting to string.

Request

Please update the vendored in to a version that includes the upstream fix (once merged), so that LibreSign users are no longer affected by this error.

Environment
  • Nextcloud version: 33.0.5.1
  • LibreSign vendored pdfparser commit:
  • PHP version: 8.x
  • Triggered by: Uploading a EncodingAsIndirectPDFObject.pdf PDF with Type1 fonts using indirect references
Nextcloud Log
Workaround

Until the vendored library is updated, the fix can be applied manually to:
3rdparty/composer/smalot/pdfparser/src/Smalot/PdfParser/Font.php

Replace the Encoding line in getDetails() with:

\$encoding = \$this->has('Encoding') ? \$this->get('Encoding') : null;
if (\$encoding instanceof PDFObject) {
    \$baseEncoding = \$encoding->getHeader()->get('BaseEncoding');
    \$details['Encoding'] = (\$baseEncoding instanceof Element && (string) \$baseEncoding !== '')
        ? (string) \$baseEncoding
        : 'Ansi';
} elseif (\$encoding instanceof Element) {
    \$details['Encoding'] = (string) \$encoding;
} else {
    \$details['Encoding'] = 'Ansi';
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with 3rdparty/composer/smalot/pdfparser/src/Smalot/PdfParser/Font.php and check the vendored smalot/pdfparser version or commit. Compare it with upstream issue #822 and pull request #823, then verify the dependency update against the supplied EncodingAsIndirectPDFObject.pdf case. Done means the vendored version includes the upstream fix and the PDF upload no longer throws the PHP 8 TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.