You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/10/24 18:38:34 UTC

[couchdb] branch prototype/fdb-layer updated: Add a special error for an invalid legacy local doc revsion

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new 3ded0e5  Add a special error for an invalid legacy local doc revsion
3ded0e5 is described below

commit 3ded0e5a0b503289937bb9db7a40fd18f0810d3d
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Oct 24 14:30:01 2019 -0400

    Add a special error for an invalid legacy local doc revsion
    
    Since we are dealing with upgrades and both versions start out as binaries,
    make sure we add extra belts and suspenders to surface any issues with encoding
    errors.
---
 src/fabric/src/fabric2_fdb.erl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index dc80311..c59346e 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -532,8 +532,13 @@ get_local_doc_rev(_Db0, <<?LOCAL_DOC_PREFIX, _/binary>> = DocId, Val) ->
     case Val of
         <<131, _/binary>> ->
             % Compatibility clause for an older encoding format
-            {Rev, _} = binary_to_term(Val, [safe]),
-            Rev;
+            try binary_to_term(Val, [safe]) of
+                {Rev, _} -> Rev;
+                _ -> erlang:error({invalid_local_doc_rev, DocId, Val})
+            catch
+                error:badarg ->
+                    erlang:error({invalid_local_doc_rev, DocId, Val})
+            end;
         <<_/binary>> ->
             try binary_to_integer(Val) of
                 IntVal when IntVal >= 0 ->