Commit Graph

65 Commits

Author SHA1 Message Date
Antoine Pitrou db983a7c38 Followup to #7703: a2b_hqx() didn't follow the new buffer API (neither in trunk
nor in py3k).  Patch by Florent Xicluna as well as additional tests.
2010-01-16 17:45:56 +00:00
Antoine Pitrou c391ad007b Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
1-byte argument.  Patch by Victor Stinner.
2010-01-15 00:18:00 +00:00
Antoine Pitrou fd3a60d5ef Issue #7703: Add support for the new buffer API to functions of the
binascii module.  Backported from py3k by Florent Xicluna, with some
additional tests.
2010-01-14 16:27:09 +00:00
Gregory P. Smith 9d53457e59 Merge in release25-maint r60793:
Added checks for integer overflows, contributed by Google. Some are
 only available if asserts are left in the code, in cases where they
 can't be triggered from Python code.
2008-06-11 07:41:16 +00:00
Gregory P. Smith dd96db63f6 This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
2008-06-09 04:58:54 +00:00
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Gregory P. Smith aef3e529e2 On platforms without zlib, make this do the right thing and return the python
2.x signed value.  Also, don't waste space on a table full of unsigned longs
when all it needs are unsigned ints (incase anyone builds this without zlib on
a 64-bit unix for some strange reason).

tested by forcing it to compile this version on both 32-bit and 64-bit linux.
2008-03-25 07:46:07 +00:00
Gregory P. Smith 1fa588e14f Use a 32-bit unsigned int here, a long is not needed. 2008-03-25 07:31:28 +00:00
Gregory P. Smith 440ca772f3 Have the binascii module use zlib's optimized crc32() function when available
to reduce our code size (1k data table and tiny bit of code).  It falls back
to its own without zlib.
2008-03-24 00:08:01 +00:00
Gregory P. Smith c856fa811d Add a test to make sure zlib.crc32 and binascii.crc32 return the same thing.
Fix a buglet in binascii.crc32, the second optional argument could previously
have a signedness mismatch with the C variable its going into.
2008-03-18 22:27:41 +00:00
Walter Dörwald 3ebc45d602 Backport checkin:
Fix a segfault when b"" was passed to b2a_qp() -- it was using strchr()
instead of memchr().
2007-05-09 18:10:47 +00:00
Georg Brandl 4aef7275cb Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters
with ASCII value less than 32. Also, it correctly quotes dots only if
they occur on a single line, as opposed to the previous behavior of
quoting dots if they are the second character of any line.
2007-03-13 22:49:43 +00:00
Georg Brandl 25aabf4cbb Bug #1588217: don't parse "= " as a soft line break in binascii's
a2b_qp() function, instead leave it in the string as quopri.decode()
does.
2006-11-16 17:08:45 +00:00
Brett Cannon 6ee7d01c05 Make binascii.hexlify() use s# for its arguments instead of t# to actually
match its documentation stating it accepts any read-only buffer.
2006-06-08 16:23:04 +00:00
Georg Brandl 2cfaa34dfa Correct some value converting strangenesses. 2006-05-29 19:39:45 +00:00
Thomas Wouters 7087f78dbe Use Py_ssize_t for arithmetic on Py_ssize_t's, instead of unsigned ints. 2006-03-01 23:10:05 +00:00
Thomas Wouters 9c54448715 Fix brainfart. 2006-03-01 21:59:44 +00:00
Thomas Wouters f98db65e52 Make Py_ssize_t-clean. 2006-03-01 21:37:32 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Neal Norwitz 1ac754fa10 Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
2006-01-19 06:09:39 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Raymond Hettinger 9fd5e9a695 Remove redunandant assertions from last checkin. 2004-09-06 23:02:37 +00:00
Raymond Hettinger 658717ed11 SF #1022953: binascii.a2b_hqx("") raises SystemError
Several functions adopted the strategy of altering a full lengthed
string copy and resizing afterwards.  That would fail if the initial
string was short enough (0 or 1) to be interned.  Interning precluded
the subsequent resizing operation.

The solution was to make sure the initial string was at least two
characters long.

Added tests to verify that all binascii functions do not crater when
given an empty string argument.
2004-09-06 22:58:37 +00:00
Martin v. Löwis b600fe90a7 Switch arguments to memset (kudos to MSVC C4318 for finding that) 2004-07-27 15:03:53 +00:00
Neal Norwitz fe92eef85b Valgrind was reporting an uninitialized read for bad input.
This fixes the problem and the test passes.  I'm not sure
the test is really correct though.  It seems like it would
be better to raise an exception.  I think that wasn't done
for backwards compatability.

Bugfix candidate.
2004-06-06 20:13:10 +00:00
Barry Warsaw 23164a5ca7 In order to fix SF bug # 824977, we replace calloc()/free() calls in
binascii_a2b_qp() and binascii_b2a_qp() with calls to PyMem_Malloc() and
PyMem_Free().  These won't return NULL unless the allocations actually fail,
so it won't trigger a bogus memory error on some platforms <cough>AIX</cough>
when passed a length of zero.
2004-05-11 02:05:11 +00:00
Thomas Wouters 9e1c192525 binascii_a2b_base64: Properly return an empty string if the input was all
invalid, rather than returning a string of random garbage of the
    estimated result length. Closes SF patch #703471 by Hye-Shik Chang.

Will backport to 2.2-maint (consider it done.)
2003-03-17 11:24:29 +00:00
Barry Warsaw 0a51b58e6b base64.decodestring('') should return '' instead of raising an
exception.  The bug fix for SF #430849 wasn't quite right.  This
closes SF bug #595671.  I'll backport this to Python 2.2.
2002-08-15 22:14:24 +00:00
Mark Hammond fe51c6d66e Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
for Py_Main().

Thanks to Kalle Svensson and Skip Montanaro for the patches.
2002-08-02 02:27:13 +00:00
Tim Peters 934c1a1c6b Another stab at SF 576327: zipfile when sizeof(long) == 8
binascii_crc32():  The previous patch forced this to return the same
result across platforms.  This patch deals with that, on a 64-bit box,
the *entry* value may have "unexpected" bits in the high four bytes.

Bugfix candidate.
2002-07-02 22:24:50 +00:00
Tim Peters a98011c388 Fix for SF bug #576327: zipfile when sizeof(long) == 8
binascii_crc32():  Make this return a signed 4-byte result across
platforms.  The other way to make this platform-independent would be to
make it return an unsigned unbounded int, but the evidence suggests
other code out there treats it like a signed 4-byte int (e.g., existing
code writing the result with struct.pack "l" format).

Bugfix candidate.
2002-07-02 20:20:08 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Tim Peters 1fbb577ee2 SF bug #494738: binascii_b2a_base64 overwrites memory.
binascii_b2a_base64():  We didn't allocate enough buffer space for very
short inputs (e.g., a 1-byte input can produce a 5-byte output, but we
only allocated 2 bytes).  I expect that malloc overheads absorbed the
overrun in practice, but computing a correct upper bound is a very simple
change.
2001-12-19 04:41:35 +00:00
Guido van Rossum 355bc0c88e Change the limit on the input size for b2a_base64 to what will fit in
memory, rather than the standard's 57.

This fixes SF bug #473009.
2001-10-30 03:00:52 +00:00
Greg Ward a645b30294 Add various typecasts (back and forth from char * to unsigned char *)
to make the SGI C compiler happier (bug #445960).
2001-10-04 14:54:53 +00:00
Martin v. Löwis 16dc7f44b1 Patch #462190, patch #464070: Support quoted printable in the binascii module.
Decode and encode underscores for header style encoding. Fixes bug #463996.
2001-09-30 20:32:11 +00:00
Peter Schneider-Kamp d895b20da0 This closes bug #430849 (internal error produced by binascii.a2b_base64) 2001-06-07 05:51:36 +00:00
Guido van Rossum 92d8917f83 Address a bug in the uuencode decoder, reported bu "donut" in SF bug
#127718: '@' and '`' seem to be confused.
2001-01-09 02:11:57 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Tim Peters b59ab42487 Fix new compiler warnings. Unused var in compile.c. Argsize mismatches
in binascii.c (only on platforms with signed chars -- although Py_CHARMASK
is documented as returning an int, it only does so on platforms with
signed chars).
2000-08-15 16:41:26 +00:00
Barry Warsaw 16168477eb binascii_unhexlify(): Better error message, courtesy effbot. 2000-08-15 06:59:58 +00:00
Barry Warsaw e977c210cb After a brief conversation and code review with TP, adding two very
commonly used functions to convert an arbitrary binary string into
a hexadecimal digit representation and back again.  These are often
(and often differently) implemented in Python.  Best to have one
common fast implementation.  Specifically,

binascii_hexlify(): a.k.a. b2a_hex() to return the hex representation
of binary data.

binascii_unhexlify(): a.k.a. a2b_hex() to do the inverse conversion
(hex digits to binary data).  The argument must have an even length,
and must contain only hex digits, otherwise a TypeError is raised.
2000-08-15 06:07:13 +00:00
Andrew M. Kuchling e365fb8d1f Use METH_VARARGS instead of numeric constant 1 in method def. tables 2000-08-03 02:06:16 +00:00
Thomas Wouters f3f33dcf03 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
and a couple of functions that were missed in the previous batches. Not
terribly tested, but very carefully scrutinized, three times.

All these were found by the little findkrc.py that I posted to python-dev,
which means there might be more lurking. Cases such as this:

long
func(a, b)
	long a;
	long b; /* flagword */
{

and other cases where the last ; in the argument list isn't followed by a
newline and an opening curly bracket. Regexps to catch all are welcome, of
course ;)
2000-07-21 06:00:07 +00:00
Peter Schneider-Kamp a788a7f0fb ANSI-fication 2000-07-10 09:57:19 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Guido van Rossum 7d47c9e38a Patch by Jim Ahlstrom to add crc32, a useful checksum function
(e.g. used for ZIP files).

The patch includes code that says:
+  Copyright (C) 1986 Gary S. Brown.  You may use this program, or
+  code or tables extracted from it, as desired without restriction.

My interpretation (and Jim's) is that Gary S Brown has no claims under
copyright, patent or other rights or interests.  Lawyers might disagree.
2000-02-16 21:11:52 +00:00
Guido van Rossum 2db4f47fdd Patch by Jason Trowbridge. (Followup to his PR#110.) (Slightly
reformatted.)

- Illegal padding is now ignored.  (Recommendation by GvR.)

- Padding no longer removes characters from data string (resulting in
lost data/strings with negative lengths).

- Illegal characters outside the ASCII range are now ignored, instead
of possibly being remapped to a valid character.
1999-10-19 19:05:14 +00:00
Guido van Rossum eba24bb920 Fix PR#110 -- bad input ("====") for a2b_base64() caused it to call
_PyString_Resize() with a negative size.
1999-10-19 04:47:13 +00:00