creswick / StreamingQR

Apache License 2.0
2 stars 0 forks source link

Fix OutOfMemory error from troublesomeQRCodes/3.png #22

Closed creswick closed 10 years ago

creswick commented 10 years ago

Imported from trac #22.

When Receive reads a QR code with value for totalChunks that is fairly large, the !BitSet may fail to initialize with an !OutOfMemory error.

To fix this, we'll likely need to do the following:

  1. Know how much memory is available to the app on the phone.
  2. Calculate the largest capacity that we can initialize the !DecodeState with that will not crash the app on the phone.
  3. Throw a parse error if we try to read a QR code with totalChunks > largest capacity for phone.
  4. Depending on calculated capacity, we may be able to reduce the number of bytes that we've reserved for the totalChunks and chunkId.
creswick commented 10 years ago

We can prevent this by limiting the max size of the bitset (eg. to the number of QR codes collected from 10 minutes of use).

Where we put this limit is still a challenge -- it's not a limit that's related to the QRLib library, since a different platform may have different limititations. Passing in a parameter to Receive(...) may work. (that defaults to ~3000 if unspecified?)

creswick commented 10 years ago

ready for code review; changes are on the ticket-22 branch.

I did a bit of generic cleanup on this ticket, which may complicate review... The main change starts in Constants.java, where the max chunks limit is set -- following usage of that variable should bring up all the other semantic changes.

I also added/moved test cases to exercise the bug.

creswick commented 10 years ago

I've merged this with master, but the branch and ticket remain for code review.

donpdonp commented 10 years ago

Specifying the max chunks to the QR code generator, and limit checking against the generated chunks seems fine to me. approved with no comments.