Skip to content

[Bug]: $nrOfBytes must be greater than 0, -324 given #295

Closed

Description

@horstoeko

Is there an existing issue for this?

  • I have searched the existing issues and found no similar reports

Are you using the latest version of this package?

  • The issue I'm reporting exists in the latest release

Can other PDF readers read the file?

  • The PDF I'm trying to read opens correctly in at least one other PDF reader

When running this snippet

$pdfParser = new PdfParser();
$pdfParsed = $pdfParser->parseString($pdfContent);
$fileSpecs = $pdfParsed->getCatalog()->getFileSpecifications();

$fileSpecs = array_filter(
    $fileSpecs,
    static function ($fileSpec) {
        return !is_null($fileSpec->getEmbeddedFile());
    }
);

foreach ($fileSpecs as $fileSpec) {
    $this->attachmentList[] = new Attachment(
        $fileSpec->getEmbeddedFile()->getStream()->toString(),
        $fileSpec->getFileSpecificationString(),
        ltrim($fileSpec->getEmbeddedFile()->getSubType() ?? '', '/')
    );
}

The error occurs when calling "$fileSpec->getEmbeddedFile()->getStream()->toString(),"

I run into the following issue/exception (Please attach the pdf)

pdf_zf_en16931_2.pdf

/home/user/vendor/prinsfrank/pdfparser/src/Stream/InMemoryStream.php:26
/home/user/vendor/prinsfrank/pdfparser/src/Document/Object/Item/CompressedObject/CompressedObjectContent/CompressedObjectContentParser.php:27
/home/user/vendor/prinsfrank/pdfparser/src/Document/Object/Item/UncompressedObject/UncompressedObject.php:89
/home/user/vendor/prinsfrank/pdfparser/src/Document/Object/Decorator/DecoratedObject.php:33

Do you allow attachment files to be used in tests to prevent regressions?

  • Yes, I give permission to use this file as a test file to prevent future regressions (And am authorized to give this permission)

Activity

  1. PrinsFrank commented on Dec 23, 2025

    @PrinsFrank
    Owner

    Sorry for the late reply, I was on holiday for a bit. I have found the issue here, the parser currently doesn't handle nested object markers properly, where a PDF object contains a bunch of other PDF objects. I'll keep you updated on a fix!

  2. PrinsFrank commented on Dec 23, 2025

    @PrinsFrank
    Owner

    I wrote a naive implementation for backward marker search from the next byte offset for objects, but that doesn't work on incrementally updated PDFs. I'll look at a more thorough implementation over the next few days, I'll keep you updated about a proper fix!

    Do you see this issue in multiple embedded PDFs or is this a bug that only occurs with some files?

  3. horstoeko commented on Dec 24, 2025

    @horstoeko
    Author

    Hi @PrinsFrank

    Thank you very much for your support. It's not that urgent – enjoy the Christmas holidays.

    Do you see this issue in multiple embedded PDFs or is this a bug that only occurs with some files?

    I will indeed need to check that. At the moment, I have only come across this one PDF. I have not yet looked at the other sample PDFs from the official ZUGFeRD/Factur-X documentation.

    Kind regards and happy Christmas

  4. niranjanbai commented on Mar 7, 2026

    @niranjanbai

    I occasionally notice this issue occurring on our server as well.

    $nrOfBytes must be greater than 0, 0 given

    Any update on fixing this issue?

  5. horstoeko commented on May 8, 2026

    @horstoeko
    Author

    Hi @PrinsFrank

    I saw that you've released a new version – I'm glad to hear that, as I'd already thought the project had been abandoned... Unfortunately, the bug mentioned in that issue is still there. How can I help?

    Kind regards

  6. PrinsFrank commented on May 9, 2026

    @PrinsFrank
    Owner

    @horstoeko sorry about the delay. I've written some context in #320. In short: I'm back! And I'll fix this soon! I just need to find a few hours to focus on this, I'll keep you updated!

  7. horstoeko commented on May 9, 2026

    @horstoeko
    Author

    Hi @PrinsFrank

    It’s really good to hear from you. I hope you’re well. I’m also delighted that you may have found a solution to my problem. I look forward to hearing from you or reading your reply.

  8. PrinsFrank commented on May 21, 2026

    @PrinsFrank
    Owner

    @niranjanbai I've fixed issues with support for PDF files within PDF files. If you do see this with other files, please open a new issue. ;)

  9. PrinsFrank commented on May 21, 2026

    @PrinsFrank
    Owner

    @horstoeko This has been fixed! I'll release an alpha release for v3 soon, (that also supports encrypted PDFs), can you try the main branch for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions