Fix crash in de-serialiser (#2289)

why:
  Late change from `Hash256` to `HashKey` without fully updating
  the serialiser.
This commit is contained in:
Jordan Hrycaj 2024-06-04 10:38:11 +00:00 committed by GitHub
parent f926222fec
commit cc909c99f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 11 deletions

View File

@ -170,7 +170,7 @@ proc blobify*(lSst: SavedState): Blob =
# ------------- # -------------
proc deblobify( proc deblobifyTo(
data: openArray[byte]; data: openArray[byte];
pyl: var PayloadRef; pyl: var PayloadRef;
): Result[void,AristoError] = ): Result[void,AristoError] =
@ -229,7 +229,7 @@ proc deblobify(
pyl = pAcc pyl = pAcc
ok() ok()
proc deblobify*( proc deblobifyTo*(
record: openArray[byte]; record: openArray[byte];
vtx: var VertexRef; vtx: var VertexRef;
): Result[void,AristoError] = ): Result[void,AristoError] =
@ -293,7 +293,7 @@ proc deblobify*(
if not isLeaf: if not isLeaf:
return err(DeblobLeafGotExtPrefix) return err(DeblobLeafGotExtPrefix)
var pyl: PayloadRef var pyl: PayloadRef
? record.toOpenArray(0, pLen - 1).deblobify(pyl) ? record.toOpenArray(0, pLen - 1).deblobifyTo(pyl)
vtx = VertexRef( vtx = VertexRef(
vType: Leaf, vType: Leaf,
lPfx: pathSegment, lPfx: pathSegment,
@ -309,11 +309,11 @@ proc deblobify*(
): Result[T,AristoError] = ): Result[T,AristoError] =
## Variant of `deblobify()` for vertex deserialisation. ## Variant of `deblobify()` for vertex deserialisation.
var vtx = T(nil) # will be auto-initialised var vtx = T(nil) # will be auto-initialised
? data.deblobify vtx ? data.deblobifyTo vtx
ok vtx ok vtx
proc deblobify*( proc deblobifyTo*(
data: openArray[byte]; data: openArray[byte];
vGen: var seq[VertexID]; vGen: var seq[VertexID];
): Result[void,AristoError] = ): Result[void,AristoError] =
@ -337,10 +337,10 @@ proc deblobify*(
): Result[T,AristoError] = ): Result[T,AristoError] =
## Variant of `deblobify()` for deserialising the vertex ID generator state ## Variant of `deblobify()` for deserialising the vertex ID generator state
var vGen: T var vGen: T
? data.deblobify vGen ? data.deblobifyTo vGen
ok move(vGen) ok move(vGen)
proc deblobify*( proc deblobifyTo*(
data: openArray[byte]; data: openArray[byte];
lSst: var SavedState; lSst: var SavedState;
): Result[void,AristoError] = ): Result[void,AristoError] =
@ -350,9 +350,13 @@ proc deblobify*(
return err(DeblobWrongSize) return err(DeblobWrongSize)
if data[^1] != 0x7f: if data[^1] != 0x7f:
return err(DeblobWrongType) return err(DeblobWrongType)
(addr lSst.src.data[0]).copyMem(unsafeAddr data[0], 32) func loadHashKey(data: openArray[byte]): Result[HashKey,AristoError] =
(addr lSst.trg.data[0]).copyMem(unsafeAddr data[32], 32) var w = HashKey.fromBytes(data).valueOr:
lSst.serial = uint64.fromBytesBE data[64..72] return err(DeblobHashKeyExpected)
ok move(w)
lSst.src = ? data.toOpenArray(0, 31).loadHashKey()
lSst.trg = ? data.toOpenArray(32, 63).loadHashKey()
lSst.serial = uint64.fromBytesBE data.toOpenArray(64, 71)
ok() ok()
proc deblobify*( proc deblobify*(
@ -361,7 +365,7 @@ proc deblobify*(
): Result[T,AristoError] = ): Result[T,AristoError] =
## Variant of `deblobify()` for deserialising a last saved state data record ## Variant of `deblobify()` for deserialising a last saved state data record
var lSst: T var lSst: T
? data.deblobify lSst ? data.deblobifyTo lSst
ok move(lSst) ok move(lSst)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------