summaryrefslogtreecommitdiff
path: root/src/Erebos/Object
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-10-08 23:06:24 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-10-08 23:06:24 +0200
commit818688ab0242a5d4329f9a690e6c119e4b3d34da (patch)
treea415c9d45cdd182985806d42e05dde2f2afb6f5d /src/Erebos/Object
parent3399d09c698953dfda8935eda8b87f1c402ae785 (diff)
Handle invalid record objects
Changelog: Gracefully handle invalid record objects
Diffstat (limited to 'src/Erebos/Object')
-rw-r--r--src/Erebos/Object/Internal.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Erebos/Object/Internal.hs b/src/Erebos/Object/Internal.hs
index fdb587a..4604f13 100644
--- a/src/Erebos/Object/Internal.hs
+++ b/src/Erebos/Object/Internal.hs
@@ -236,11 +236,14 @@ unsafeDeserializeObject st bytes =
(line, rest) | Just (otype, len) <- splitObjPrefix line -> do
let (content, next) = first BL.toStrict $ BL.splitAt (fromIntegral len) $ BL.drop 1 rest
guard $ B.length content == len
- (,next) <$> case otype of
- _ | otype == BC.pack "blob" -> return $ Blob content
- | otype == BC.pack "rec" -> maybe (throwOtherError $ "malformed record item ")
- (return . Rec) $ sequence $ map parseRecLine $ mergeCont [] $ BC.lines content
- | otherwise -> return $ UnknownObject otype content
+ (, next) <$> if
+ | otype == BC.pack "blob"
+ -> return $ Blob content
+ | otype == BC.pack "rec"
+ , Just ritems <- sequence $ map parseRecLine $ mergeCont [] $ BC.lines content
+ -> return $ Rec ritems
+ | otherwise
+ -> return $ UnknownObject otype content
_ -> throwOtherError $ "malformed object"
where splitObjPrefix line = do
[otype, tlen] <- return $ BLC.words line