Commit Graph

56 Commits

Author SHA1 Message Date
Durham Goode
8c6e5fd964 mpatch: add rust bindings
Summary:
Adds rust bindings around the existing mpatch c library.

Also fixes a bug in mpatch where it could reference uninitialized memory.

Reviewed By: quark-zju

Differential Revision: D7769299

fbshipit-source-id: bcc21df85c97ef6f5537ebff8fbf1b350ee64fc3
2018-05-14 16:06:32 -07:00
Augie Fackler
44f638de23 mpatch: switch alignment of wrapped line from tab to spaces with clang-format
I may be a weird person for liking this style, but our C style is
historically nominally the Linux Kernel style, and when you configure
clang-format to be kernel-ish, this is what you get. If we want to
change it, we can do so by tweaking the formatter rules in the future.

Differential Revision: https://phab.mercurial-scm.org/D1132
2017-10-04 11:00:04 -04:00
Augie Fackler
210a208635 mpatch: reformat function prototypes with clang-format
Differential Revision: https://phab.mercurial-scm.org/D1131
2017-10-04 10:56:33 -04:00
Augie Fackler
f4d56c2a16 mpatch: reflow two oddly formatted else blocks with clang-format
Differential Revision: https://phab.mercurial-scm.org/D1029
2017-10-04 10:57:23 -04:00
Augie Fackler
0455ba8dfd mpatch: re-wrap wide line with clang-format
Differential Revision: https://phab.mercurial-scm.org/D1027
2017-10-04 10:55:51 -04:00
Yuya Nishihara
17d165938d mpatch: raise MemoryError instead of mpatchError if lalloc() failed
MemoryError is handled differently in dispatch._runcatch().

Since mpatch_errors[] isn't that useful now, I've changed it to a simple
switch statement.
2016-08-07 10:06:56 +09:00
Yuya Nishihara
f46414cb1e mpatch: change lalloc() to local function
It was mistakenly made public at 73648c4dacb9.
2016-08-07 09:40:30 +09:00
Yuya Nishihara
932006e32f mpatch: remove superfluous whitespaces 2016-08-07 09:49:07 +09:00
Maciej Fijalkowski
8d7ca5fe20 mpatch: remove dependency on Python.h in mpatch.c
Now all the CPython-related stuff are referenced only from
mpatch_module.c with mpatch.c being freely usable from
a future cffi module
2016-07-22 17:28:05 +02:00
Maciej Fijalkowski
3bdeeb5959 mpatch: split mpatch into two files 2016-07-18 19:02:30 +02:00
Maciej Fijalkowski
3d64f15242 mpatch: provide things that will be exported later with a prefixed name
For cffi a bunch of mpatch functions need to be visible through a .h file.
This change renames them so it won't create potential c namespace conflicts.
2016-07-18 16:25:14 +02:00
Maciej Fijalkowski
43e619711a mpatch: change Py_ssize_t to ssize_t in places that will be later copied 2016-07-18 15:14:40 +02:00
Maciej Fijalkowski
8e7a874bdf internals: move the bitmanipulation routines into its own file
This is to allow more flexibility with the C sources -- now the
bitmanipulation routines can be safely imported without importing Python.h
2016-06-06 13:08:13 +02:00
timeless
4fca2b2f02 mpatch: unify mpatchError (issue5182)
The pure version was mpatch was throwing struct.error or ValueError
for errors, whereas the C version was throwing an "mpatch.mpatchError".

Introducing an mpatch.mpatchError into pure and using it consistently
is fairly easy, but the actual form for it is mercurial.mpatch.mpatchError,
so with this commit, we change the C implementation to match the naming
convention too.
2016-03-31 02:05:28 +00:00
Matt Mackall
b81aafc379 parsers: detect short records (SEC)
CVE-2016-3630 (2/2)

This addresses part of a vulnerability in binary delta application.
2016-03-16 17:30:26 -07:00
Matt Mackall
4622bdc826 parsers: fix list sizing rounding error (SEC)
CVE-2016-3630 (1/2)

This addresses part of a vulnerability in application of binary
deltas.
2016-03-16 17:29:29 -07:00
Matt Mackall
c4f5764d33 mpatch: rewrite pointer overflow checks 2013-12-11 18:33:42 -06:00
Adrian Buehlmann
3a26ebacab mpatch: use Py_ssize_t for string length 2012-05-20 01:28:31 +02:00
Adrian Buehlmann
96bc6f8416 mpatch: use Py_ssize_t
Eliminates

  mpatch.c(73) : warning C4244: 'return' : conversion from '__int64' to 'int',
  possible loss of data
  mpatch.c(299) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data
  mpatch.c(321) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int',
  possible loss of data
  mpatch.c(335) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data
  mpatch.c(346) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data

when compiling for Windows x64 target using the Microsoft compiler.
2012-05-20 00:08:18 +02:00
Matt Mackall
0fa9895915 util.h: replace ntohl/htonl with get/putbe32 2012-04-16 11:26:00 -05:00
Matt Mackall
fd4256c9b1 util.h: unify some common platform tweaks 2012-04-10 12:07:14 -05:00
Matt Mackall
935d420846 util.h: move Py_ssize_t bits from mpatch.c 2012-04-10 12:07:09 -05:00
Matt Mackall
cb69aaee4e parsers: avoid pointer aliasing
Newer versions of GCC have aggressive pointer alias optimizations that
might get fooled by our pointer manipulations. These issues shouldn't
be encountered in practice because distutils compiles extensions with
-fno-strict-alias but the code was not valid according to the standard.
2011-08-10 13:40:01 -05:00
Martin Geisler
a76e121863 backout of e4cb9628354c
Matt and a majority of crew did not like this approach.
2011-01-27 11:15:08 +01:00
Martin Geisler
d23e1973c2 specify C indention style using Emacs file local variables 2011-01-26 12:05:01 +01:00
Renato Cunha
f8467c0605 mpatch.c: Added preliminary support for py3k.
This is done by including the util.h header file, that defines appropriate
macros according to the current python version.
2010-06-15 19:49:56 -03:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Scott McCreary
501e6fe68f allow Mercurial to compile on Haiku 2008-09-17 10:22:35 +02:00
Shun-ichi GOTO
bc6b138bfb mpatch: Define Py_ssize_t for old pythons and use it instead of ssize_t.
See also PEP 353.
NOTE: Microsoft compilers (8 or earlier) does not have ssize_t.
2007-10-12 11:46:49 +09:00
Matt Mackall
507b4b92da mpatch: allow buffer objects for input 2007-10-11 00:46:45 -05:00
Thomas Arendsen Hein
b4fc156022 merge with stable 2007-04-25 18:43:55 +02:00
Thomas Arendsen Hein
2f0fd5e3bc Fix segfaults when parsing bdiff hunks in mpatch.decode() and .patchedsize()
- fix off by 11 when checking if there are more hunks (found by Maris Fogels)
- bail out if start is greater than end
- check if new hunk starts after start/end/len block of current hunk as
  the pointer can wrap around on very large values, reproducible with
  import mpatch; mpatch.patchedsize(12, 'x'*12)
2007-01-27 23:07:06 +01:00
Andrew Bachmann
3b2c3dac24 BeOS compatibility support 2007-01-02 21:40:20 -08:00
Matt Mackall
f61dd23d9b mpatch: Fix for malloc corner case on AIX 2006-09-21 16:16:39 -05:00
Vadim Gelfer
dc377b58c1 update copyrights. 2006-08-12 12:30:02 -07:00
Thomas Arendsen Hein
5088fdd568 Include inttypes.h instead of stdint.h (fixes issue299)
Many projects use inttypes.h, too. stdint.h isn't available everywhere, e.g.
on some versions of Solaris, while inttypes.h is available everywhere where
stdint.h is.
2006-06-30 21:41:46 +02:00
Vadim Gelfer
e18ca75a83 mac os x: fixes for 10.2 from chris monson <monpublic@gmail.com> 2006-06-20 17:51:39 -07:00
Chris Mason
b52474f560 merge 0.8.1 with revlogng 2006-04-08 20:10:46 -04:00
Thomas Arendsen Hein
faa1c52566 Set correct exception for another possible malloc error in mpatch.c 2006-04-05 15:39:48 +02:00
mason@suse.com
492b52fda3 Fill in the uncompressed size during revlog.addgroup
This uses code from Matt to calculate the size change that
would result from applying a delta to keep an accurate running
total of the text size during revlog.addgroup
2006-04-04 16:38:44 -04:00
TK Soh
9681381233 do proper typecasting on malloc() and calloc() calls
to support build on Solaris 2.6 using Sun Pro SC4.0 (C++ 4.1) compiler.
2006-03-20 08:46:29 +01:00
Thomas Arendsen Hein
8d6e52f81a Fixed misleading indentation in mpatch.c 2006-02-18 16:31:02 +01:00
Benoit Boissinot
af35f643ab catch errors and throw exception with invalid binary patch data 2006-02-15 04:37:47 +01:00
mpm@selenic.com
eee2ab41c0 [PATCH] use <arpa/inet.h> instead of <netinet/in.h> for ntohl/htonl
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[PATCH] use <arpa/inet.h> instead of <netinet/in.h> for ntohl/htonl

From: Jed Davis <jdev@panix.com>

This fixes the Mac OS X build problem; hopefully it won't break any
other OSes, especially since SUSv3 says arpa/inet is the right header.
( http://www.opengroup.org/onlinepubs/009695399/functions/ntohl.html )

manifest hash: 2f06ff0cffefdb35e794131afcd1f34f9fdfa5cf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCyEoFywK+sNU5EO8RAk6WAJ9v/pnr07zUXKM9EBQQGaKSZAlhxACdHrwS
XTLSL6pPGAwaRfExGF2A3DQ=
=Rtv9
-----END PGP SIGNATURE-----
2005-07-03 12:26:45 -08:00
mpm@selenic.com
68e36bb922 [PATCH] bdiff/mpatch under MSVC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[PATCH] bdiff/mpatch under MSVC

From: K Thananchayan <thananck@yahoo.com>

MSVC (6.0) environment does not have 'stdint.h' and does not provide
`inline' qualifier. The following patch is needed to make mecurial
installable under MSVC.

manifest hash: a5b64235acced16cb451faa698922559fec4e573
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCxPapywK+sNU5EO8RAmRnAKCt9cOASaIsYB6kNUDSIStR1DmY4gCgnXlL
Jf0nMmGEkoyXtB0eV+fLzJU=
=fKD5
-----END PGP SIGNATURE-----
2005-06-30 23:54:17 -08:00
mpm@selenic.com
a053dfbfab More fiddling with uint32_t includes for extensions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

More fiddling with uint32_t includes for extensions

manifest hash: 1ad16a0262e9bd2769e32c13c7fd0c7b0cd7dde7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCwS+/ywK+sNU5EO8RAhK1AKCtF/57nKCc1AU+l0sR74kHhY1NCwCfSvQK
QQc5i8abuGkFpU5VUBJt5XQ=
=H+CX
-----END PGP SIGNATURE-----
2005-06-28 03:08:47 -08:00
mpm@selenic.com
fad4970cee Remove stdint.h from mpatch and bdiff
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Remove stdint.h from mpatch and bdiff

It's only there for ntohl and htonl and should be pulled in by in.h.

manifest hash: 65954290279241ac92c9ce04c21cf1a3c9dd54e0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCwD8KywK+sNU5EO8RAhv2AJ40R/T72XK63IbeEFqMLSRJbRJWdACcDa9r
dOL9XpyYxR09REbAHw0JrlE=
=8wkZ
-----END PGP SIGNATURE-----
2005-06-27 10:01:46 -08:00
mpm@selenic.com
44ac4156e1 extensions: use stdint.h
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

extensions: use stdint.h

Not sure why I didn't do this the first time around. Hopefully still
builds everywhere.

manifest hash: 965582286a190728f8cc0dfb8e11ee56628a59a5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCvfRgywK+sNU5EO8RAg9SAJ4/ZVpQZcDY5xovLDTZK2txEegEgwCdF2b+
lzSIP109qq8D+KIdUWsbEPc=
=+0Yy
-----END PGP SIGNATURE-----
2005-06-25 16:18:40 -08:00
kyle@zeus.moffetthome.net
b724addd44 Added stdint.h include to fix build on Mac OS X Tiger [v10.4] 2005-06-24 20:53:51 -05:00
mpm@selenic.com
4266c33df9 Add 'other OS' bits to bdiff.c / style cleanups
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Add 'other OS' bits to bdiff.c / style cleanups

manifest hash: 9a0ef60a59af0594f95a2b22de243fe8ef059762
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCuNL0ywK+sNU5EO8RAg+yAKCe8dG411HdZZvsxB25AtfBBApQBQCgnb7O
MGO0xvEBgAtt+3F+VJBkiU4=
=F7r7
-----END PGP SIGNATURE-----
2005-06-21 18:54:44 -08:00