Show More
@@ -44,6 +44,13 class StorageError(Hint, Exception): | |||
|
44 | 44 | class RevlogError(StorageError): |
|
45 | 45 | __bytes__ = _tobytes |
|
46 | 46 | |
|
47 | class SidedataHashError(RevlogError): | |
|
48 | ||
|
49 | def __init__(self, key, expected, got): | |
|
50 | self.sidedatakey = key | |
|
51 | self.expecteddigest = expected | |
|
52 | self.actualdigest = got | |
|
53 | ||
|
47 | 54 | class FilteredIndexError(IndexError): |
|
48 | 55 | __bytes__ = _tobytes |
|
49 | 56 |
@@ -1675,7 +1675,13 class revlog(object): | |||
|
1675 | 1675 | validatehash = flagutil.processflagsraw(self, rawtext, flags) |
|
1676 | 1676 | text = rawtext |
|
1677 | 1677 | else: |
|
1678 | try: | |
|
1678 | 1679 | r = flagutil.processflagsread(self, rawtext, flags) |
|
1680 | except error.SidedataHashError as exc: | |
|
1681 | msg = _("integrity check failed on %s:%s sidedata key %d") | |
|
1682 | msg %= (self.indexfile, pycompat.bytestr(rev), | |
|
1683 | exc.sidedatakey) | |
|
1684 | raise error.RevlogError(msg) | |
|
1679 | 1685 | text, validatehash, sidedata = r |
|
1680 | 1686 | if validatehash: |
|
1681 | 1687 | self.checkhash(text, node, rev=rev) |
@@ -32,3 +32,32 the concept. | |||
|
32 | 32 | """ |
|
33 | 33 | |
|
34 | 34 | from __future__ import absolute_import |
|
35 | ||
|
36 | import hashlib | |
|
37 | import struct | |
|
38 | ||
|
39 | from .. import error | |
|
40 | ||
|
41 | SIDEDATA_HEADER = struct.Struct('>H') | |
|
42 | SIDEDATA_ENTRY = struct.Struct('>HL20s') | |
|
43 | ||
|
44 | def sidedatareadprocessor(rl, text): | |
|
45 | sidedata = {} | |
|
46 | offset = 0 | |
|
47 | nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | |
|
48 | offset += SIDEDATA_HEADER.size | |
|
49 | dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) | |
|
50 | for i in range(nbentry): | |
|
51 | nextoffset = offset + SIDEDATA_ENTRY.size | |
|
52 | key, size, storeddigest = SIDEDATA_ENTRY.unpack(text[offset:nextoffset]) | |
|
53 | offset = nextoffset | |
|
54 | # read the data associated with that entry | |
|
55 | nextdataoffset = dataoffset + size | |
|
56 | entrytext = text[dataoffset:nextdataoffset] | |
|
57 | readdigest = hashlib.sha1(entrytext).digest() | |
|
58 | if storeddigest != readdigest: | |
|
59 | raise error.SidedataHashError(key, storeddigest, readdigest) | |
|
60 | sidedata[key] = entrytext | |
|
61 | dataoffset = nextdataoffset | |
|
62 | text = text[dataoffset:] | |
|
63 | return text, True, sidedata |
General Comments 0
You need to be logged in to leave comments.
Login now