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

BUG: Add the TK.SIZE into the trailer #1911

Merged
merged 2 commits into from
Jun 26, 2023
Merged

BUG: Add the TK.SIZE into the trailer #1911

merged 2 commits into from
Jun 26, 2023

Conversation

talcher
Copy link
Contributor

@talcher talcher commented Jun 23, 2023

Closes #1901

@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.01 ⚠️

Comparison is base (cd4c9d8) 93.83% compared to head (adde37b) 92.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1911      +/-   ##
==========================================
- Coverage   93.83%   92.83%   -1.01%     
==========================================
  Files          34       34              
  Lines        6943     7058     +115     
  Branches     1370     1389      +19     
==========================================
+ Hits         6515     6552      +37     
- Misses        282      359      +77     
- Partials      146      147       +1     
Impacted Files Coverage Δ
pypdf/_reader.py 91.33% <100.00%> (ø)

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@MartinThoma
Copy link
Member

Looks fine to me.

From "Table 15 – Entries in the file trailer dictionary" of the 1.7 specs:

(Required; shall not be an indirect reference) The total number of entries in
the file’s cross-reference table, as defined by the combination of the original
section and all update sections. Equivalently, this value shall be 1 greater
than the highest object number defined in the file.

Any object in a cross-reference section whose number is greater than this
value shall be ignored and defined to be missing by a conforming reader.

I wonder why this wasn't observed earlier.

@pubpub-zz What do you think?

@pubpub-zz
Copy link
Collaborator

Mod looks good. Can you just a check that the /Size is present:
I propose just to add at the end of one test to confirm Size will not disappear (picked up randomly 😉):

@pytest.mark.enable_socket()
    def test_append_forms():
    # from #1538
    writer = PdfWriter()

    url = "https://github.com/py-pdf/pypdf/files/10367412/pdfa.pdf"
    name = "form_a.pdf"
    reader1 = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
    reader1.add_form_topname("form_a")
    writer.append(reader1)

    url = "https://github.com/py-pdf/pypdf/files/10367413/pdfb.pdf"
    name = "form_b.pdf"
    reader2 = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
    reader2.add_form_topname("form_b")
    writer.append(reader2)

    b = BytesIO()
    writer.write(b)
    reader = PdfReader(b)
    assert len(reader.get_form_text_fields()) == len(
        reader1.get_form_text_fields()
    ) + len(reader2.get_form_text_fields())
   assert "/Size" in reader.trailer                          # <----  added

@talcher
Copy link
Contributor Author

talcher commented Jun 26, 2023

The check is added. I hope the test I chose is OK for you.
The problem is: a codecov check is unsuccessful and the PR does not have a green tick anymore, but a red cross.
Any idea to correct that?

@MartinThoma MartinThoma changed the title Add the TK.SIZE into the trailer BUG: Add the TK.SIZE into the trailer Jun 26, 2023
@MartinThoma MartinThoma merged commit fcf5cca into py-pdf:main Jun 26, 2023
@MartinThoma
Copy link
Member

Thank you for the contribution! The fix is now in main. A new version of pypdf will be on PyPI latest on Sunday (2nd of June, 2023)

@MartinThoma
Copy link
Member

If you want, I can add you to https://pypdf.readthedocs.io/en/latest/meta/CONTRIBUTORS.html :-)

MartinThoma added a commit that referenced this pull request Jul 2, 2023
New Features (ENH):
-  Add AES support for encrypting PDF files (#1918, #1935, #1936, #1938)
-  Add page deletion feature to PdfWriter (#1843)

Bug Fixes (BUG):
-  PdfReader.get_fields() attempts to delete non-existing index "/Off" (#1933)
-  Remove unused objects when cloning_from (#1926)
-  Add the TK.SIZE into the trailer (#1911)
-  add_named_destination() maintains named destination list sort order (#1930)
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

Successfully merging this pull request may close these issues.

Missing "Size" info in the trailer
3 participants