Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In FdpiFacturx, the SetPdfVersion function is broken. #40

Closed
Billy-1971 opened this issue Feb 24, 2025 · 4 comments
Closed

In FdpiFacturx, the SetPdfVersion function is broken. #40

Billy-1971 opened this issue Feb 24, 2025 · 4 comments
Assignees

Comments

@Billy-1971
Copy link

In FdpiFacturx, the SetPdfVersion function is broken.

PHP chr only accepts values from 0-255, values from 127-256 are generated via rand.

Therefore, from time to time the PDF is not valid, error: The aforementioned EOL marker shall be immediately followed by a % (25h) character followed by at least four bytes, each of whose encoded byte values shall have a decimal value greater than 127

Original:
$this->PDFVersion .= "\n" . '%' . chr(rand(128, 256)) . chr(rand(128, 256)) . chr(rand(128, 256)) . chr(rand(128, 256));
New:
$this->PDFVersion .= "\n" . '%' . chr(rand(127, 255)) . chr(rand(127, 255)) . chr(rand(127, 255)) . chr(rand(127, 255)); // chr 0-255

@benito103e
Copy link
Member

benito103e commented Feb 25, 2025

Hello,
Thank you for your issue, please don't be offended by my question: but are you human?
If so, in what context did you encounter this error?
Thank you in advance for your clarification, before I dig deeper into the subject.

@benito103e benito103e self-assigned this Feb 25, 2025
@Billy-1971
Copy link
Author

Billy-1971 commented Feb 25, 2025

Hello,
i am a human, i come from Germany and unfortunately my English is very bad, so I have partially machine translated the text.

The problem occurs when i create a ZUGFeRD PDF from a PDF and a facturx.xml using Writer via "generate". The problem occurs approximately once every 30-50 times.

The error message comes from the Verapdf Validator, because i validate each PDF after it is created.

@benito103e
Copy link
Member

Hello Billy,
Thanks for your answer,
In fact, chr(256) is equivalent to chr(0) regarding the doc : https://www.php.net/

I've never encountered any problems with these binary content declaration characters (Perhaps VeraPDF is stricter), but it would indeed be a good idea to improve this.

ISO 32000-1:2008, Section 7.5.2 (File Header)

If a PDF file contains binary data, as most do (see 7.2, "Lexical Conventions"), the header line shall be
immediately followed by a comment line containing at least four binary characters—that is, characters whose
codes are 128 or greater. This ensures proper behaviour of file transfer applications that inspect data near the
beginning of a file to determine whether to treat the file’s contents as text or as binary.

I'm submitting a PR.

@benito103e
Copy link
Member

Fixed by #41
New release v2.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants