@@ -1,3 +1,10 @@
1+-- WARNING: This file is security sensitive as it uses unsafeWrite which does
2+-- not check bounds. Any changes should be made with care and I would love to
3+-- get informed about them, just cc me in any PR targetting this file: @eskimor
4+-- I would be happy to review the changes!
6+-- The security check at the end (pos > length) only works if pos grows
7+-- monotonously, if this condition does not hold, the check is flawed.
1module Data.Aeson.Parser.UnescapePure
8module Data.Aeson.Parser.UnescapePure
3 unescapeText
10 unescapeText
@@ -145,8 +152,8 @@ unescapeText' bs = runText $ \done -> do
145 dest <- A.new len
152 dest <- A.new len
146 (pos, finalState) <- B.foldl' (f' dest) (return (0, StateNone)) bs
153 (pos, finalState) <- B.foldl' (f' dest) (return (0, StateNone)) bs
148− -- Check final state.
155+ -- Check final state. Currently pos gets only increased over time, so this check should catch overflows.
149− when ( finalState /= StateNone)
156+ when ( finalState /= StateNone || pos > len)
150 throwDecodeError
157 throwDecodeError
152 done dest pos -- TODO: pos, pos-1??? XXX
159 done dest pos -- TODO: pos, pos-1??? XXX