matrix-org / gomatrixserverlib

Go library for matrix federation.
Apache License 2.0
62 stars 51 forks source link

Bad JSON: value is outside of safe range #257

Closed ferologics closed 3 years ago

ferologics commented 3 years ago

Problem

When sending a [video] message to the room via Matrix iOS SDK client to https://server_endpoint/_matrix/client/r0/rooms/!roomId:host/send/m.room.message/messageId with following request body:

{"body":"video_5e1f43c.mp4","info":{"duration":30466.666666666664,"thumbnail_url":"mxc:\/\/localhost\/e76b28e344ae8c388cc19e42fb7eb73d397b1931001a0fd62f26f199d1b3cd1a","mimetype":"video\/mp4","w":480,"h":270,"thumbnail_info":{"size":0,"mimetype":"image\/jpeg","w":0,"h":0}},"url":"mxc:\/\/localhost\/55e9366d7a68d7970b8071145d631745d36231a4f2eeccab366a61f8ef521626","msgtype":"m.video"}

we get an unexpected error:

{
    "errcode": "M_BAD_JSON",
    "error": "gomatrixserverlib: bad JSON: value is outside of safe range"
}

This suggests that the request body is invalid JSON -- at least according to the Canonical JSON Appendix.

I went ahead and verified the JSON grammar according to RFC7159 standard via https://jsonformatter.curiousconcept.com which successfully validated the JSON ![image](https://user-images.githubusercontent.com/5576161/114703208-47ddc880-9d25-11eb-8251-2366349821f7.png)
I decided to validate the JSON error myself with a custom go script which converts the request body JSON to byte array and validates it against gomatrixserverlib CanonicalJSON() and EnforcedCanonicalJSON(). image

This showed that the JSON is invalid in the case of the Room Version 6.

To my understanding this should't happen?

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

Go script for validating the failing request body can be found here

tulir commented 3 years ago

The error is correct and should happen, floats aren't allowed in canonical JSON.

ferologics commented 3 years ago

Yes! Thanks 👍 closing this in favor of https://github.com/matrix-org/matrix-ios-sdk/issues/1070