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

PDF::Core::Stream has wrong length for multi-byte string #62

Open
sled opened this issue Nov 13, 2024 · 0 comments
Open

PDF::Core::Stream has wrong length for multi-byte string #62

sled opened this issue Nov 13, 2024 · 0 comments

Comments

@sled
Copy link

sled commented Nov 13, 2024

I discovered, that PDF::Core::Stream#length returns the wrong length if a multi-byte string is used, i.e:

content = <<~XMP
  <?xpacket begin="\u{FEFF}" id="W5M0MpCehiHzreSzNTczkc9d"?>
  <?xpacket end="w"?>
XMP

puts "CONTENT BYTESIZE: #{content.bytesize}"

stream_1 = PDF::Core::Stream.new
stream_1 << content
puts "STREAM LENGTH #1: #{stream_1.length} << WRONG"

stream_2 = PDF::Core::Stream.new
stream_2 << content.force_encoding('BINARY')
puts "STREAM LENGTH #2: #{stream_2.length}"

outputs:

CONTENT BYTESIZE: 74
STREAM LENGTH #1: 72 << WRONG
STREAM LENGTH #2: 74

I think this line in PDF::Core::Stream#length should use String#bytesize instead of String#length

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

No branches or pull requests

1 participant