Skip to content

Commit cf0cbb2

Browse files
committed
Switch cffi flag default.
Also added on additional check in the pure parser, which should catch buffer overflows hopefully soon enough to prevent any harm.
1 parent 83f2830 commit cf0cbb2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

aeson.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ flag bytestring-builder
7474
manual: False
7575

7676
flag cffi
77-
description: Controls whether to include c-ffi bits or pure haskell
78-
default: True
77+
description: Controls whether to include c-ffi bits or pure haskell. Default to False for security.
78+
default: False
7979
manual: True
8080

8181
library

pure/Data/Aeson/Parser/UnescapePure.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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!
5+
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.
18
module Data.Aeson.Parser.UnescapePure
29
(
310
unescapeText
@@ -145,8 +152,8 @@ unescapeText' bs = runText $ \done -> do
145152
dest <- A.new len
146153
(pos, finalState) <- B.foldl' (f' dest) (return (0, StateNone)) bs
147154

148-
-- Check final state.
149-
when ( finalState /= StateNone)
155+
-- Check final state. Currently pos gets only increased over time, so this check should catch overflows.
156+
when ( finalState /= StateNone || pos > len)
150157
throwDecodeError
151158

152159
done dest pos -- TODO: pos, pos-1??? XXX

0 commit comments

Comments
 (0)