Patchwork D9169: tags: add safety check for len(record) while reading hgtagsfnodescache

login
register
mail settings
Submitter phabricator
Date Oct. 7, 2020, 9:49 a.m.
Message ID <differential-rev-PHID-DREV-f4qrghgufyydqmy4umya-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47398/
State Superseded
Headers show

Comments

phabricator - Oct. 7, 2020, 9:49 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9169

AFFECTED FILES
  mercurial/tags.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -759,7 +759,7 @@ 
         properprefix = node[0:4]
 
         # Validate and return existing entry.
-        if record != _fnodesmissingrec:
+        if record != _fnodesmissingrec and len(record) == _fnodesrecsize:
             fileprefix = record[0:4]
 
             if fileprefix == properprefix: