Bug 6356 - Import patch from URL broken
Summary: Import patch from URL broken
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: python3 (show other bugs)
Version: unspecified
Hardware: All All
: critical bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-15 06:59 UTC by Cédric Krier
Modified: 2020-08-19 00:00 UTC (History)
1 user (show)

See Also:
Python Version: ---


Attachments
Fill chunks only when readinto is not used (557 bytes, patch)
2020-06-15 14:43 UTC, Cédric Krier
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cédric Krier 2020-06-15 06:59 UTC
On Python3 importing a patch from an URL for which the content is greater than 8096 creates sometimes wrong result. The content of some lines modified is duplicated.
I traced the bug to the HTTPResponse.readline method in combination with HTTPResponse.readinto.
The readline method append to the chunks the content of the _rbuf then there is a loop that call _raw_read which on Python3 call readinto. But the readinto version in mercurial append again the _rbuf content. So this creates the duplicate content. This does not happen in Python2 because _raw_read does not call readinto.

I do not know what is the best solution:

- not append _rbuf content in readinto
- not fill buffer with _rbuf in readline on Python3 (it is needed on Python2).
Comment 1 Cédric Krier 2020-06-15 14:43 UTC
Created attachment 2076 [details]
Fill chunks only when readinto is not used

Here is my proposal.
Comment 2 Pierre-Yves David 2020-07-08 20:38 UTC
This looks quite serious. Can you look into sending you patch through our official means: https://www.mercurial-scm.org/wiki/ContributingChanges
Comment 3 Bugzilla 2020-07-19 00:00 UTC
Bug marked urgent for 10 days, bumping
Comment 4 Bugzilla 2020-07-30 00:03 UTC
Bug marked urgent for 10 days, bumping
Comment 5 Cédric Krier 2020-08-02 11:46 UTC
(In reply to Pierre-Yves David from comment #2)
https://phab.mercurial-scm.org/D8859
Comment 6 HG Bot 2020-08-11 12:25 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/49f8ba4febec
Cédric Krier <ced@b2ck.com>
keepalive: Do not append _rbuf if _raw_readinto exists (issue6356)

The readline method append to the chunks the content of the _rbuf then there
is a loop that call _raw_read which on Python3 call readinto. But the readinto
version in mercurial append again the _rbuf content. So this creates the
duplicate content. This does not happen in Python2 because _raw_read does not
call readinto.

Differential Revision: https://phab.mercurial-scm.org/D8859

(please test the fix)
Comment 7 Bugzilla 2020-08-19 00:00 UTC
Bug was set to TESTING for 7 days, resolving