Scratch-vm: 10240 limit for variables

Created on 30 Jan 2018  路  6Comments  路  Source: LLK/scratch-vm

Expected Behavior

Variables never have over 10240 charactors in 2.0. If we can, it may be able to make the PC crashed

Actual Behavior

It can have.

Steps to Reproduce

program: see image

Operating System and Browser

win7 homepremium 64bit SP1
firefox 58.0.1

bug compatibility has patch has-patch

Most helpful comment

The hack in 2.0 to make really long strings/numbers was to make a list of single-character items and use the list reporter to stringify it. Since the limitation on list length in 3.0 is 200k, if we really need a cap on variable length maybe that'd be an appropriate one, since it's the same length that that old hack would cap out at anyway.

I doubt any 2.0 projects depended on the join block's 10240 character limit. It could probably change to 200k too so all the string-related things are consistent.

All 6 comments

Variables never have over 10240 charactors in 2.0. If we can, it may be able to make the PC crashed

How would having a lot of characters in a variable make a computer crash?

I honestly think this feature of Scratch 2.0 is an unnecessary limitation. Having a lot of text in a variable doesn't inherently do anything bad - and it certainly dosen't crash the computer. After all, it's just a few more string bytes. Costumes and sounds, and even the project JSON/XML (which can obviously greater than 10240 characters in length), take up far more memory.

What might be a bigger performance hit would be trying to display all that text at once. Theoretically, a speech bubble or a monitor containing that much text could take a lot of memory. But there's an obvious limitation to that: cut off the text; don't display all the characters. Limit the display to a sane amount, not the data.

Also, fwiw I believe the limitation was actually with the join block, there are projects that use other tricks to create long variables and those projects would break if this limit was placed on variables themselves

I just stumbled onto this again, and discussed briefly with @rschamp @BryceLTaylor and @thisandagain. Basically, because Scratch 3.0 can e.g. concatenate strings very fast, you can very quickly get a result like this- a variable containing a string almost 300 million characters long!

screen shot 2018-11-29 at 11 00 43 am

If I had just started with one banana, and did join my var my var, that might have only taken a few seconds (and probably quickly crashed the browser tab).

I eventually got this error:

scratch3_operators.js:94 Uncaught RangeError: Invalid string length
    at Scratch3OperatorsBlocks.join (scratch3_operators.js:94)

Here's a better repro. It maxes out immediately with the console error, at a little over 900 million characters:

screen shot 2018-11-29 at 11 13 26 am

Is it necessary to add this limit? It would be nice to not have to use weird hacks to join things over 10240 characters in length.

The hack in 2.0 to make really long strings/numbers was to make a list of single-character items and use the list reporter to stringify it. Since the limitation on list length in 3.0 is 200k, if we really need a cap on variable length maybe that'd be an appropriate one, since it's the same length that that old hack would cap out at anyway.

I doubt any 2.0 projects depended on the join block's 10240 character limit. It could probably change to 200k too so all the string-related things are consistent.

Was this page helpful?
0 / 5 - 0 ratings