Skip to content

Commit ca72111

Browse files
committed
Merge branch 'release-v0.28.1' into develop
2 parents 2ad3fc3 + d5eee5d commit ca72111

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

synapse/api/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
"""Contains constants from the specification."""
1818

19+
# the "depth" field on events is limited to 2**63 - 1
20+
MAX_DEPTH = 2**63 - 1
21+
1922

2023
class Membership(object):
2124

synapse/federation/federation_base.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
# limitations under the License.
1515
import logging
1616

17-
from synapse.api.errors import SynapseError
17+
import six
18+
19+
from synapse.api.constants import MAX_DEPTH
20+
from synapse.api.errors import SynapseError, Codes
1821
from synapse.crypto.event_signing import check_event_content_hash
1922
from synapse.events import FrozenEvent
2023
from synapse.events.utils import prune_event
@@ -190,11 +193,23 @@ def event_from_pdu_json(pdu_json, outlier=False):
190193
FrozenEvent
191194
192195
Raises:
193-
SynapseError: if the pdu is missing required fields
196+
SynapseError: if the pdu is missing required fields or is otherwise
197+
not a valid matrix event
194198
"""
195199
# we could probably enforce a bunch of other fields here (room_id, sender,
196200
# origin, etc etc)
197-
assert_params_in_request(pdu_json, ('event_id', 'type'))
201+
assert_params_in_request(pdu_json, ('event_id', 'type', 'depth'))
202+
203+
depth = pdu_json['depth']
204+
if not isinstance(depth, six.integer_types):
205+
raise SynapseError(400, "Depth %r not an intger" % (depth, ),
206+
Codes.BAD_JSON)
207+
208+
if depth < 0:
209+
raise SynapseError(400, "Depth too small", Codes.BAD_JSON)
210+
elif depth > MAX_DEPTH:
211+
raise SynapseError(400, "Depth too large", Codes.BAD_JSON)
212+
198213
event = FrozenEvent(
199214
pdu_json
200215
)

synapse/handlers/message.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from twisted.internet import defer, reactor
2323
from twisted.python.failure import Failure
2424

25-
from synapse.api.constants import EventTypes, Membership
25+
from synapse.api.constants import EventTypes, Membership, MAX_DEPTH
2626
from synapse.api.errors import AuthError, Codes, SynapseError
2727
from synapse.crypto.event_signing import add_hashes_and_signatures
2828
from synapse.events.utils import serialize_event
@@ -625,6 +625,10 @@ def create_new_client_event(self, builder, requester=None,
625625

626626
if prev_events_and_hashes:
627627
depth = max([d for _, _, d in prev_events_and_hashes]) + 1
628+
# we cap depth of generated events, to ensure that they are not
629+
# rejected by other servers (and so that they can be persisted in
630+
# the db)
631+
depth = min(depth, MAX_DEPTH)
628632
else:
629633
depth = 1
630634

0 commit comments

Comments
 (0)