Skip to content

RQRCode::QRCodeRunTimeError: code length overflow. (372>288) #15

Closed
meetme2meat opened this Issue Apr 3, 2012 · 12 comments

9 participants

@meetme2meat

When Generating "QRCode" the following above error was generated

The the string whose Qrcode is resulting in error

"http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_div_align"

The Code

 RQRCode::QRCode.new("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_div_align", :size => 4, :level => :h )
RQRCode::QRCodeRunTimeError: code length overflow. (540>288)
@4poc
4poc commented Apr 11, 2012

+1 got the same error

@plapinhh
plapinhh commented May 3, 2012

+1 the same.

i've fixed it by increasing the :size option's value ( RQRCode::QRCode.new( url.to_s, :size => 10, :level => :l) ) and controlling my urls length...

but, i have not yet looked what the mean is...

@meetme2meat

@plapinhh Try a really long string and check does it break

@j03w
j03w commented Sep 2, 2012

QR code version 4 with high level error correction give you maximum length of 50 alphanumeric characters

Follow the link to see full matrix of maximum capacity for each version:

http://www.qrcode.com/en/vertable1.html

@jamesprior

Note that the chart gives some guidelines but it looks like the rqrcode library is not using any of the numeric or alphanumeric modes, only data.

Eg:

irb(main):003:0> text = "a"*50
=> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
irb(main):004:0> text.length
=> 50
irb(main):005:0> qr = RQRCode::QRCode.new(text, :size => 3, :level => :m)
RQRCode::QRCodeRunTimeError: code length overflow. (412>352)

It looks like I'm passing 50 characters, and at size 3 level m the chart says the limit is 61. Instead it errors and tells me that there are more data bits than allowed.

@digerata

I'm hitting this same problem as well. My testing shows it only uses the binary mode. I thought passing message using str.encode("us-ascii") might trigger alphanumeric, but it doesn't.

@jamesprior

FWIW, I ended up just putting my QR code generation inside a loop to find the best fit size. It is Not Great but functional. I post it as a way to illustrate what I'm talking about but please take a critical look before using it anywhere else.

  qr_size = 3
  qr = nil
  while qr == nil && qr_size < 10
    begin
      qr = RQRCode::QRCode.new(qr_data, :size => qr_size, :level => :l)
    rescue RQRCode::QRCodeRunTimeError => e
      qr_size += 1
    end
  end
@digerata

That's a good tip. Thanks!

Digging through the code, I've found there is no support for any mode except binary. I'm quite surprised by that. Check out QR8bitByte and QRCode classes. I was hoping to create a new QRAlphaByte class, but I'm not familiar enough with the code to create something that works.

@digerata

Okay, this is the guy to use: https://github.com/bjornblomqvist/rqrcode

Lot's of progress on the code here, including the ability to encode alphanumeric.

@haslo
haslo commented Oct 13, 2014

Very cool, thanks 👍 using the fixed version then 😄

@mmcraedhcu

I've had mostly great results with rqrcode-with-patches, with one exception.

You can view details here bjornblomqvist@whomwah:master...master

From my experience (and I encourage you to test this for yourself), RQRCode::QRCode.new(qr_text) fails, throwing 'code length overflow' when 194 < qr_text.length < 221

It's a bizarre bug -- normally it auto-selects the proper size very well. Can anyone else confirm / comment on this?

@wallace wallace added a commit to wallace/secret_santa that referenced this issue Mar 20, 2015
@wallace wallace Switches to rqrcode-with-patches
from whomwah/rqrcode#15 (comment)

it seems that rqrcode has been abandoned so i'm using the recommended one:
https://github.com/bjornblomqvist/rqrcode
4cafbee
@bdewater bdewater referenced this issue in samvincent/rqrcode-rails3 Apr 10, 2015
Open

Consider the rqrcode-with-patches gem #18

@bjornblomqvist
Collaborator

I have added a hint in the error on how to fix it.

RQRCode::QRCodeRunTimeError: code length overflow. (540>288) (Try a larger size!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.