dwitter-net / dwitter-frontend

Social network for short js demos, frontend for github.com/lionleaf/dwitter
https://beta.dwitter.net
Apache License 2.0
23 stars 13 forks source link

Compressor fix for unicode chars smaller than \uD000. Fixes #107 #109

Closed CiaccoDavide closed 2 years ago

CiaccoDavide commented 2 years ago

Issue: it's possible to use non-ASCII characters in variables names, for example 限 = 1337

is \u9650

since this unicode character's most significant digit isn't D, \u9650 is split by the decompressor in two different ASCII characters 96 and 50 (as in \u0096 and \u0050 or escaped: %96 and %50).

While \u0050 is P, \u0096 is not a valid character, hence the error: image

is a good character because when it's split into two different characters the first is invalid, but the second is a valid one! (P) And most importantly the variable P was not defined along with so when we compress it, there are no conflicts!

If you want to test it, try compressing d/24278 with a compressor like this one. Then when you'll decompress it again (replacing eval with throw for example...) you'll see that was split and only P was kept!

This PR solves this kind of edge cases, where the unicode variable name is replaced upon compression by a valid and unused ASCII character.

If that variable was called then we'd still have a problem, because that character (being \u9608) is split into \u0096 (ignored) and \u0008 (invalid)

An other example of error that I think can't be avoided can be tested by using (\u9678) as a variable name because the compression result would be x (\u0078) is already defined and used by dwitter (and while javascript allows it to be redefined it would probably lead to errors, for example if something like x.fillRect is used)


Both this compression errors can be tested with https://xem.github.io/obfuscatweet/ and code like this dweet's: https://dwitter.net/d/24278

works both uncompressed and compressed (original code)

限=199
for(m=-限;m<限;m+=(2+t))for(n=-限;n<限;n+=(3+t)){
g=2*m*n
b=m*m+n*n
r=m*m-n*n
x.fillRect(1920/2+frame*g/b,1080/2+frame*r/b,1,1)}

works uncompressed but not compressed, cause: SyntaxError: illegal character U+0008

阈=199
for(m=-阈;m<阈;m+=(2+t))for(n=-阈;n<阈;n+=(3+t)){
g=2*m*n
b=m*m+n*n
r=m*m-n*n
x.fillRect(1920/2+frame*g/b,1080/2+frame*r/b,1,1)}

works uncompressed but not compressed, cause: TypeError: x.fillRect is not a function

陸=199
for(m=-陸;m<陸;m+=(2+t))for(n=-陸;n<陸;n+=(3+t)){
g=2*m*n
b=m*m+n*n
r=m*m-n*n
x.fillRect(1920/2+frame*g/b,1080/2+frame*r/b,1,1)}
lionleaf commented 2 years ago

deployed