diff --git a/Data/Text/Encoding.hs b/Data/Text/Encoding.hs
index b1c39c780e058123247fa3ed044eab57786f4321..f21e6a29cfc351d1c83234fc25dfb63736d7ab98 100644
--- a/Data/Text/Encoding.hs
+++ b/Data/Text/Encoding.hs
@@ -267,6 +267,7 @@ streamDecodeUtf8With onErr = decodeChunk B.empty 0 0
                 UTF8_REJECT -> do
                   -- We encountered an encoding error
                   x <- peek curPtr'
+                  poke statePtr 0
                   case onErr desc (Just x) of
                     Nothing -> loop $ curPtr' `plusPtr` 1
                     Just c -> do
@@ -274,7 +275,6 @@ streamDecodeUtf8With onErr = decodeChunk B.empty 0 0
                       w <- unsafeSTToIO $
                            unsafeWrite dest (fromIntegral destOff) (safe c)
                       poke destOffPtr (destOff + fromIntegral w)
-                      poke statePtr 0
                       loop $ curPtr' `plusPtr` 1
 
                 _ -> do