Patchwork [2,of,4,STABLE,follow-up] streamclone: use readexactly when reading stream v2

login
register
mail settings
Submitter Boris Feld
Date Jan. 26, 2018, 4:07 p.m.
Message ID <ba834f589608bfc7ad88.1516982850@FB>
Download mbox | patch
Permalink /patch/27066/
State Accepted
Headers show

Comments

Boris Feld - Jan. 26, 2018, 4:07 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1516826671 -3600
#      Wed Jan 24 21:44:31 2018 +0100
# Branch stable
# Node ID ba834f589608bfc7ad88a29b22941f322c598760
# Parent  7d4c20e651bebd76f09183681ba9d743834dc53d
# EXP-Topic b2-stream
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ba834f589608
streamclone: use readexactly when reading stream v2

Yuya Nishihara pointed out that it is safer.

Patch

diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -594,12 +594,12 @@  def consumev2(repo, fp, filecount, files
                     for vfs in vfsmap.values())
             with nested(*ctxs):
                 for i in range(filecount):
-                    src = fp.read(1)
+                    src = util.readexactly(fp, 1)
                     vfs = vfsmap[src]
                     namelen = util.uvarintdecodestream(fp)
                     datalen = util.uvarintdecodestream(fp)
 
-                    name = fp.read(namelen)
+                    name = util.readexactly(fp, namelen)
 
                     if repo.ui.debugflag:
                         repo.ui.debug('adding [%s] %s (%s)\n' %