atsign-foundation / at_server

The software implementation of Atsign's core technology
https://docs.atsign.com
BSD 3-Clause "New" or "Revised" License
39 stars 13 forks source link

Inserting a 253-character key triggers server shutdown upon restart. #1863

Closed purnimavenkatasubbu closed 5 months ago

purnimavenkatasubbu commented 5 months ago

Describe the bug

Restarting the server after inserting a key with 253 characters exits with the following error

SecondaryServerBootStrapper|Uncaught error: HiveError: Cannot read, unknown typeId: 241. Did you forget to register an adapter? StackTrace: #0 BinaryReaderImpl.read (package:hive/src/binary/binary_reader_impl.dart:325:11)

1 CommitOpAdapter.read (package:at_persistence_secondary_server/src/log/commitlog/commit_entry.dart:99:71)

2 BinaryReaderImpl.read (package:hive/src/binary/binary_reader_impl.dart:328:33)

3 BinaryReaderImpl.readEncrypted (package:hive/src/binary/binary_reader_impl.dart:342:24)

4 BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:278:26)

5 StorageBackendVm.readValue. (package:hive/src/backend/vm/storage_backend_vm.dart:111:30)

#6 _AsyncCompleter.complete (dart:async/future_impl.dart:41:3) #7 LazyBoxImpl.get (package:hive/src/box/lazy_box_impl.dart:32:19) ### Steps to reproduce 1. First Create a key with 253 characters - iujpsefqvdzmtqthrqbaxqszxokaiutvpnbcphcjvjghpdxzdwywfsaowruwafmcudeoarfhuncezjkwbdvprcbujeptisxkjtztxogqqrrnjpqrdsjmcrpmpusrkzaksdfleyzsuarjhsqvxwicxulzqjzcwwjaupxzoqfwenkfonwhxtmwamiyzqqoesnreknrzwxazvykbybafrlwgqsyreudprnakoioqiwoqiwqdebbdwbdywebwydbw 2. Then restart the server ### Expected behavior Server should not exit ### Screenshots ![Screenshot from 2024-03-26 16-42-08](https://github.com/atsign-foundation/at_server/assets/43639593/ec64590a-872c-483a-833c-7dbd07c18d31) ### Smartphones _No response_ ### Were you using an atApplication when the bug was found? _No response_ ### Additional context _No response_
gkc commented 5 months ago

Marking this as Urgent.

murali-shris commented 5 months ago

Hive impl has a check for key length > 255. But it is part of assert and works only in debug mode.

frame.dart from hive impl /// Not part of public API Frame(this.key, this.value, {this.length, this.offset = -1}) : lazy = false, deleted = false { assert(assertKey(key)); //validates for key length and throws exception } @gkc Should we add the check for key length in update handler on server and at_client put ?

gkc commented 5 months ago

I think it needs to go in the at_persistence lib first, since that's where it will end up both on client and server. Then also yes in the update verb handler and at_client's put

Also note that the problem occurs at key lengths of 253 or more. (@purnimavenkatasubbu are keys of length 252 OK?)

purnimavenkatasubbu commented 5 months ago

I think it needs to go in the at_persistence lib first, since that's where it will end up both on client and server. Then also yes in the update verb handler and at_client's put

Also note that the problem occurs at key lengths of 253 or more. (@purnimavenkatasubbu are keys of length 252 OK?)

I get this issue with key of length 252 characters as well

murali-shris commented 5 months ago

I think it needs to go in the at_persistence lib first, since that's where it will end up both on client and server. Then also yes in the update verb handler and at_client's put Also note that the problem occurs at key lengths of 253 or more. (@purnimavenkatasubbu are keys of length 252 OK?)

I get this issue with key of length 252 characters as well

key length has to be calculated along with atsign length e.g (random key of length 252 or 253 chars) + atsign length. in both the cases, key length will exceed 255 chars and result in the bug.

VJag commented 5 months ago

I think @purnimavenkatasubbu referring to the absolute length here.