packages feed

store-core 0.2.0.0 → 0.2.0.1

raw patch · 3 files changed

+22/−8 lines, 3 filesnew-uploader

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # ChangeLog +## 0.2.0.1++* Fixes a bug that could result in segfaults when reading corrupted data.+ ## 0.2.0.0  * First public release
src/Data/Store/Core.hs view
@@ -315,9 +315,10 @@ decodeIOPortionWithFromPtr :: Peek a -> Ptr Word8 -> Int -> IO (Offset, a) decodeIOPortionWithFromPtr mypeek ptr len =     let end = ptr `plusPtr` len+        remaining = end `minusPtr` ptr     in do         (ptr2, x') <- runPeek mypeek end ptr-        if ptr2 > end+        if len > remaining -- Do not perform the check on the new pointer, since it could have overflowed             then throwIO $ PeekException (end `minusPtr` ptr2) "Overshot end of buffer"             else return (ptr2 `minusPtr` ptr, x') {-# INLINE decodeIOPortionWithFromPtr #-}@@ -349,7 +350,7 @@         needed = sizeOf (undefined :: a)         remaining = end `minusPtr` ptr      in do-        when (ptr' > end) $+        when (needed > remaining) $ -- Do not perform the check on the new pointer, since it could have overflowed             tooManyBytes needed remaining ty         x <- Storable.peek (castPtr ptr)         return (ptr', x)@@ -370,6 +371,7 @@                       len         let !newOffset = targetOffset + len         return (newOffset, ())+{-# INLINE pokeFromForeignPtr #-}  -- | Allocate a plain ForeignPtr (no finalizers), of the specified -- length and fill it with bytes from the input.@@ -377,12 +379,14 @@ peekToPlainForeignPtr ty len =     Peek $ \end sourcePtr -> do         let ptr2 = sourcePtr `plusPtr` len-        when (ptr2 > end) $-            tooManyBytes len (end `minusPtr` sourcePtr) ty+            remaining = end `minusPtr` sourcePtr+        when (len > remaining) $ -- Do not perform the check on the new pointer, since it could have overflowed+            tooManyBytes len remaining ty         fp <- BS.mallocByteString len         withForeignPtr fp $ \targetPtr ->             BS.memcpy targetPtr (castPtr sourcePtr) len         return (ptr2, castForeignPtr fp)+{-# INLINE peekToPlainForeignPtr #-}  -- | Copy a section of memory, based on a 'Ptr', to the output. Note -- that this operation is unsafe, because the offset and length@@ -395,6 +399,7 @@                   len         let !newOffset = targetOffset + len         return (newOffset, ())+{-# INLINE pokeFromPtr #-}  -- TODO: have a safer variant with the check? @@ -408,6 +413,7 @@         copyByteArrayToAddr sourceArr sourceOffset target len         let !newOffset = targetOffset + len         return (newOffset, ())+{-# INLINE pokeFromByteArray #-}  -- | Allocate a ByteArray of the specified length and fill it with bytes -- from the input.@@ -415,19 +421,23 @@ peekToByteArray ty len =     Peek $ \end sourcePtr -> do         let ptr2 = sourcePtr `plusPtr` len-        when (ptr2 > end) $-            tooManyBytes len (end `minusPtr` sourcePtr) ty+            remaining = end `minusPtr` sourcePtr+        when (len > remaining) $ -- Do not perform the check on the new pointer, since it could have overflowed+            tooManyBytes len remaining ty         marr <- newByteArray len         copyAddrToByteArray sourcePtr marr 0 len         x <- unsafeFreezeByteArray marr         return (ptr2, x)+{-# INLINE peekToByteArray #-}  -- | Wrapper around @copyByteArrayToAddr#@ primop. copyByteArrayToAddr :: ByteArray# -> Int -> Ptr a -> Int -> IO () copyByteArrayToAddr arr (I# offset) (Ptr addr) (I# len) =     IO (\s -> (# copyByteArrayToAddr# arr offset addr len s, () #))+{-# INLINE copyByteArrayToAddr  #-}  -- | Wrapper around @copyAddrToByteArray#@ primop. copyAddrToByteArray :: Ptr a -> MutableByteArray (PrimState IO) -> Int -> Int -> IO () copyAddrToByteArray (Ptr addr) (MutableByteArray arr) (I# offset) (I# len) =     IO (\s -> (# copyAddrToByteArray# addr arr offset len s, () #))+{-# INLINE copyAddrToByteArray  #-}
store-core.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.14.0.+-- This file has been generated from package.yaml by hpack version 0.14.1. -- -- see: https://github.com/sol/hpack  name:           store-core-version:        0.2.0.0+version:        0.2.0.1 synopsis:       Fast and lightweight binary serialization category:       Serialization, Data homepage:       https://github.com/fpco/store#readme