Mercurial > hg
comparison mercurial/tags.py @ 45787:225e513c444e
tags: add safety check for len(record) while reading hgtagsfnodescache
I am trying to fix a breakage where somehow we end up getting a node of 12
length from `getfnode()`. Understanding the hgtagsfnodescache code, it seems
highly unlikely that it can happen unless one of `mctx.readfast().get()` or
`ctx.filenode()` is returning a node of 12 length.
For safety, I think it's better to add a check to make sure that record which we
are parsing is of same length we are expecting otherwise we consider that as
invalid record.
Differential Revision: https://phab.mercurial-scm.org/D9169
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 07 Oct 2020 14:26:47 +0530 |
parents | 64de86fd0984 |
children | 89a2afe31e82 |
comparison
equal
deleted
inserted
replaced
45786:37c65704869d | 45787:225e513c444e |
---|---|
757 offset = rev * _fnodesrecsize | 757 offset = rev * _fnodesrecsize |
758 record = b'%s' % self._raw[offset : offset + _fnodesrecsize] | 758 record = b'%s' % self._raw[offset : offset + _fnodesrecsize] |
759 properprefix = node[0:4] | 759 properprefix = node[0:4] |
760 | 760 |
761 # Validate and return existing entry. | 761 # Validate and return existing entry. |
762 if record != _fnodesmissingrec: | 762 if record != _fnodesmissingrec and len(record) == _fnodesrecsize: |
763 fileprefix = record[0:4] | 763 fileprefix = record[0:4] |
764 | 764 |
765 if fileprefix == properprefix: | 765 if fileprefix == properprefix: |
766 self.hitcount += 1 | 766 self.hitcount += 1 |
767 return record[4:] | 767 return record[4:] |