+6
-6
atproto/data/const.go
+6
-6
atproto/data/const.go
···
7
7
MAX_CBOR_RECORD_SIZE = 1 * 1024 * 1024
8
8
// maximum serialized size of an individual atproto record, in JSON format
9
9
MAX_JSON_RECORD_SIZE = 2 * 1024 * 1024
10
-
// maximum serialized size of blocks (raw bytes) in an atproto repo stream event
10
+
// maximum serialized size of blocks (raw bytes) in an atproto repo stream event (NOT ENFORCED YET)
11
11
MAX_STREAM_REPO_DIFF_SIZE = 4 * 1024 * 1024
12
-
// maximum size of a WebSocket frame in atproto event streams
12
+
// maximum size of a WebSocket frame in atproto event streams (NOT ENFORCED YET)
13
13
MAX_STREAM_FRAME_SIZE = MAX_CBOR_SIZE
14
14
// maximum size of any individual string inside an atproto record
15
15
MAX_RECORD_STRING_LEN = MAX_CBOR_RECORD_SIZE
16
16
// maximum size of any individual byte array (bytestring) inside an atproto record
17
17
MAX_RECORD_BYTES_LEN = MAX_CBOR_RECORD_SIZE
18
-
// limit on size of CID representation
18
+
// limit on size of CID representation (NOT ENFORCED YET)
19
19
MAX_CID_BYTES = 100
20
-
// limit on depth of nested containers (objects or arrays) for atproto data
20
+
// limit on depth of nested containers (objects or arrays) for atproto data (NOT ENFORCED YET)
21
21
MAX_CBOR_NESTED_LEVELS = 32
22
22
// maximum number of elements in an object or array in atproto data
23
23
MAX_CBOR_CONTAINER_LEN = 128 * 1024
24
-
// largest integer which can be represented in a float64. integers in atproto "should" not be larger than this.
24
+
// largest integer which can be represented in a float64. integers in atproto "should" not be larger than this. (NOT ENFORCED)
25
25
MAX_SAFE_INTEGER = 9007199254740991
26
-
// largest negative integer which can be represented in a float64. integers in atproto "should" not go below this.
26
+
// largest negative integer which can be represented in a float64. integers in atproto "should" not go below this. (NOT ENFORCED)
27
27
MIN_SAFE_INTEGER = -9007199254740991
28
28
// maximum length of string (UTF-8 bytes) in an atproto object (map)
29
29
MAX_OBJECT_KEY_LEN = 8192
+7
atproto/data/data.go
+7
atproto/data/data.go
···
2
2
3
3
import (
4
4
"encoding/json"
5
+
"fmt"
5
6
6
7
"github.com/bluesky-social/indigo/atproto/syntax"
7
8
···
19
20
//
20
21
// The standard library's MarshalJSON can be used to invert this function.
21
22
func UnmarshalJSON(b []byte) (map[string]any, error) {
23
+
if len(b) > MAX_JSON_RECORD_SIZE {
24
+
return nil, fmt.Errorf("exceeded max JSON record size: %d", len(b))
25
+
}
22
26
var rawObj map[string]any
23
27
err := json.Unmarshal(b, &rawObj)
24
28
if err != nil {
···
33
37
34
38
// Parses generic data (object) in CBOR (specifically, IPLD dag-cbor), validating against the atproto data model at the same time.
35
39
func UnmarshalCBOR(b []byte) (map[string]any, error) {
40
+
if len(b) > MAX_CBOR_RECORD_SIZE {
41
+
return nil, fmt.Errorf("exceeded max CBOR record size: %d", len(b))
42
+
}
36
43
var rawObj map[string]any
37
44
err := cbor.DecodeInto(b, &rawObj)
38
45
if err != nil {