diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -83,8 +83,17 @@ def _read(self): """reads the state file and returns a dictionary which contain data in the same format as it was before storing""" - with self._repo.vfs(self.fname, 'rb') as fp: - return cbor.load(fp) + try: + with self._repo.vfs(self.fname, 'rb') as fp: + ret = cbor.load(fp) + if (not isinstance(ret, dict) or + ret.get('magicheader') != 'HGStateFile'): + raise cbor.CBORDecodeError + return ret + except cbor.CBORDecodeError: # cbor raises an Exception + with self._repo.vfs(self.fname, 'rb') as fp: + oldfn = oldstatefilefns[self.fname] + return oldfn(fp) def delete(self): """drop the state file if exists"""