View Issue Details

IDProjectCategoryView StatusLast Update
0009549New issuesMulti Theft Auto : San Andreaspublic2017-02-27 15:20
ReporterSHC//SniperAssigned Toccw 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0009549: Erroneous fromJSON parsing
Description

Check the example below. "^T^0" is parsed as a table for some reason which recently broke one of our resources. Replacing "^T^0" with "^T^1" returns nil on the other hand. Changing the string to anything other than "^T^0^" or similar fixes the problem.

Steps To Reproduce

srun tb = fromJSON('[ [ 2251, "^The^ Winners^", "^T^0", 2, 0, 0, 0, [ 102, 153, 204 ], "WRITE SOMENTHING YOU ABOUT\n\n" ] ]')

srun tb[3]

Command results: table: 0x653aa35a53c0 [table]


srun tb = fromJSON('[ [ 2251, "^The^ Winners^", "^T^1", 2, 0, 0, 0, [ 102, 153, 204 ], "WRITE SOMENTHING YOU ABOUT\n\n" ] ]')

srun tostring(tb[3])

Command results: nil [string]

TagsNo tags attached.

Activities

pkpawelo

2017-02-18 20:13

viewer   ~~0025675

Last edited: 2017-02-18 20:21

View 2 revisions

This actually gets even funnier - it is not just a random (new) table, it is a pointer to the same table which it resides in.

srun tb
Command results: table: 1B474090 [table]

srun tb[3]
Command results: table: 1B474090 [table]

srun tb[3][3][3][3][3][3][3][3][3][3][3]
Command results: table: 1B474090 [table]

I'm going to look into it.

pkpawelo

2017-02-20 23:44

viewer   ~~0025677

Last edited: 2017-02-20 23:53

View 3 revisions

Okay, after some digging I've found out that ^T^, ^E^ and ^R^ are special internal sequences used for serialization of elements, tables and resources.

If you run: srun tb = fromJSON('[ [[123], "^T^1" ] ]')
then tb[2] will be pointer to [123] table and so on.

Make sure that strings in your JSON don't start with those sequences, or else you may run into further issues.

Currently I don't have enough knowledge to come up with any reasonable solution, but this behaviour is undocumented and potentially dangerous.

SHC//Sniper

2017-02-27 01:03

reporter   ~~0025687

Is there really no way to solve this problem? FromJSON is used by many servers to store data (including user generated content). This bug can potentially be utilized to break people's resources on purpose. In our case an entire core resource was malfunctioning. We can block these internal sequences ourselves but the thousands of other servers will not be aware of this issue/risk.

ccw

2017-02-27 15:20

administrator   ~~0025688

Bodged in https://github.com/multitheftauto/mtasa-blue/commit/859e10026ba6efc1762886a190be41680dc746a0

Issue History

Date Modified Username Field Change