rameshsharma

rameshsharma

Any one has encountered error like below for a pdf encryption:-

(exit) an exception was raised:
2020-11-02T23:16:20.453666662Z     ** (RuntimeError) integer out of range converting 4294967295 from a 8-byte signed type to a 4-byte signed type
2020-11-02T23:16:20.453669462Z 
2020-11-02T23:16:20.453671862Z         (my_future_now 4.0.0) lib/my_future_now/services/encrypt_pdf_service.ex:61: MyFutureNow.EncryptPdfService.encrypt_pdf!/3
2020-11-02T23:16:20.453674663Z         (my_future_now 4.0.0) lib/my_future_now/services/encrypt_pdf_service.ex:20: MyFutureNow.EncryptPdfService.encrypt_and_write_file!/2
2020-11-02T23:16:20.453677463Z         (my_future_now 4.0.0) lib/my_future_now_web/email/loa_email.ex:90: MyFutureNowWeb.LOAEmail.employer_encrypted_loa_parts/1
2020-11-02T23:16:20.453680163Z         (my_future_now 4.0.0) lib/my_future_now_web/email/loa_email.ex:353: MyFutureNowWeb.LOAEmail.loa_email_to_employer/2

Showing Posts 1 to 8

kokolegorille

kokolegorille

You should describe what You are doing, with which tools… like this it’s hard to have any idea.

rameshsharma

rameshsharma OP

We are using
QPDF (PDF document processing)

We use qpdf for encrypting (password protecting) PDFs.

Below is the code for encrypting pdf:-

defp encrypt_pdf!(orig_path, password, opts) do
    {ext, rest} = orig_path |> String.split(".") |> List.pop_at(-1)
    new_path = Enum.join(rest ++ ["encrypted", ext], ".")

    page_range = if range = opts[:page_range], do: to_string(range), else: "1-z"

    opts =
      ["--empty", "--pages", orig_path, page_range, "--"] ++
        ["--encrypt", password, password, "128", "--use-aes=y", "--", new_path]

    case System.cmd("qpdf", opts, stderr_to_stdout: true) do
      {_, 0} -> new_path
      {err, _} -> raise(err)
    end
  end
rameshsharma

rameshsharma OP

def encrypt_and_upload!(%Document{} = orig_document, opts \\ []) do
    password = SecureRandom.urlsafe_base64(8)

    orig_document
    |> download_and_write_file!
    |> encrypt_pdf!(password, opts)
    |> upload_new!(password, orig_document)
  end

  def encrypt_and_write_file!(%Document{} = document, opts \\ []) do
    path = download_and_write_file!(document)
    password = SecureRandom.urlsafe_base64(8)

    enc_path = encrypt_pdf!(path, password, opts)

    {enc_path, password}
  end

rameshsharma

rameshsharma OP

The error logs says that the encryption is breaking, not sure where and why

(RuntimeError) integer out of range converting 4294967295 from a 8-byte signed type to a 4-byte signed type

al2o3cr

al2o3cr

RuntimeError is what raise produces; based on the stacktrace I’d guess {err, _} -> ... is on line 61.

qpdf is returning that message from deep in a utility function, unfortunately:

https://github.com/qpdf/qpdf/blob/232f5fc9f3bed8e1b02bca5d10b2eca444e30f95/include/qpdf/QIntC.hh#L72-L75

rameshsharma

rameshsharma OP

QPDF_VERSION=9.1.1 is used by us.
Will a upgrade of the version help. How to fix the issue any idea?

al2o3cr

al2o3cr

This post is the first time I’ve ever seen qpdf, so I can’t really say what the problem is.

Skimming the changelog on that repo doesn’t show any obvious “fix this exact bug” entries since 9.1.1, but it likely wouldn’t hurt to upgrade.

The next lead I’d recommend you follow is that value 4294967295 - where does it appear in the input? Does qpdf give a different error for a different input file?

Edit to add: 4294967295 is 0xFFFF_FFFF, which is what you’d get if code mistakenly interpreted a 4-byte signed -1 as a 4-byte unsigned value - not sure if that’s significant.

ku1ik

ku1ik

integer out of range converting 4294967295 from a 8-byte signed type to a 4-byte signed type is a bug in qpdf <= 1.0.4. See here https://www.gitmemory.com/issue/qpdf/qpdf/482/721737907

I had the same, upgraded qpdf to 1.0.4 and I confirm it works (also tested qpdf 1.1.0, works too).

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews