<div dir="ltr">On Thu, Jun 27, 2013 at 12:07 AM, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I would to parse an integer in [0; UINT_MAX] to fix the zlib module on<br>

64-bit system:<br>
<a href="http://bugs.python.org/issue18294" target="_blank">http://bugs.python.org/issue18294</a><br>
<br>
How should I implement that? Use "O" format and then use<br>
PyLong_Check(), PyLong_AsLong(), and check value <= UINT_MAX?<br></blockquote><div><br></div><div style>I ran into the same problem in the _lzma module. My solution was to define a custom converter that does an explicit check before returning the value (see <a href="http://hg.python.org/cpython/file/default/Modules/_lzmamodule.c#l134">http://hg.python.org/cpython/file/default/Modules/_lzmamodule.c#l134</a>).</div>
<div style><br></div><div style>On Thu, Jun 27, 2013 at 12:26 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">> I would to parse an integer in [0; UINT_MAX] to fix the zlib module on<br>
</div><div class="im">> 64-bit system:<br>> <a href="http://bugs.python.org/issue18294" target="_blank">http://bugs.python.org/issue18294</a><br>><br>> How should I implement that? Use "O" format and then use<br>
> PyLong_Check(), PyLong_AsLong(), and check value <= UINT_MAX?<br><br></div>Why can't you use the K format? It won't reject out-of-range values,<br>but it will convert them to in-range so there aren't any attacks<br>
possible based on bypassing the range check. I'm probably<br>misunderstanding something -- I don't completely understand that bug<br>report. :-(</blockquote><div><br></div><div style>The point is not to protect against deliberate attacks, but rather to fail loudly (instead of silently) when the caller provides an input that the underlying C library cannot handle.</div>
<div style><br></div><div style>- Nadeem</div></div></div></div></div></div></div>