Problem with big int addresses

Bug #1408934 reported by Alexander Belchenko
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
IntelHex
Fix Released
High
Alexander Belchenko

Bug Description

Reported by e-mail (Dayasagar Patil)

Hi Alexander,

I am using intelhex v1.1 python script (Intel HEX file format reader and converter) developed by you for processing intel hex file.
I use Python v2.5.4.

I observed an issue with the script’s tobinstr() function. This function internally calls tobinarry(), and within tobinarry(), xrange() python api is used.
I think xrange() function does not work for large integers. When I called tobinstr() with large integers as arguments,
the exception ‘OverflowError: long int too large to convert to int’ was raised.

Following is my code snippet:
Ranges = [(2684625744L, 2684625749L)]
Data = ''
for Start, End in Ranges:
    Data += Hex.tobinstr(start=Start, end=End)
print Data

I checked with the latest version 1.5 of the intel hex script, but found that it too uses xrange() (inside _tobinarray_really()).

It would be great if you could provide some details on this issue and a solution.

Thanks,
Dayasagar Patil

Tags: python2

Related branches

Revision history for this message
Alexander Belchenko (bialix) wrote :

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import intelhex
>>> ih = intelhex.IntelHex()
>>> print(ih.tobinstr(start=0x80000000, end=0x80000001))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "intelhex\__init__.py", line 381, in tobinstr
    return self._tobinstr_really(start, end, pad, size)
  File "intelhex\__init__.py", line 384, in _tobinstr_really
    return asbytes(self._tobinarray_really(start, end, pad, size).tostring())
  File "intelhex\__init__.py", line 357, in _tobinarray_really
    for i in range_g(start, end+1):
OverflowError: long int too large to convert to int

Revision history for this message
Alexander Belchenko (bialix) wrote :

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:37:12) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import intelhex
>>> ih = intelhex.IntelHex()
>>> print(ih.tobinstr(start=0x80000000, end=0x80000001))
b'\xff\xff'

Changed in intelhex:
status: New → Confirmed
tags: added: python2
Revision history for this message
Alexander Belchenko (bialix) wrote :

From bug report https://bugs.launchpad.net/intelhex/+bug/1432704:

I solved it with
 for i in lrange(start, end+1):
            bin.append(self._buf.get(i, pad))
instead of
        for i in xrange(start, end+1):
            bin.append(self._buf.get(i, pad))

        return bin

lrange downloaded from https://github.com/zed/lrange/

note it might not be optimal, but works

Revision history for this message
Alexander Belchenko (bialix) wrote :

Just a side note. I've read the code of lrange library, and it seems its implementation does not care much about performance.

Revision history for this message
Xavi (xaviertisaire) wrote : Re: [Bug 1408934] Re: Problem with big int addresses

Hello,

I totally agree, that's what I meant by "it's not optimal, but it works". I
guess it can be improved.

Xavier Tisaire
+436604851979
<email address hidden>

Warning: This e-mail is privileged, confidential and contains private
information. Any reading, retention, distribution or copying of this
communication by any person other than its intended recipient is prohibited.

On 1 April 2015 at 13:40, Alexander Belchenko <<email address hidden>
> wrote:

> Just a side note. I've read the code of lrange library, and it seems its
> implementation does not care much about performance.
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1432704).
> https://bugs.launchpad.net/bugs/1408934
>
> Title:
> Problem with big int addresses
>
> Status in IntelHex files manipulating:
> Confirmed
>
> Bug description:
> Reported by e-mail (Dayasagar Patil)
>
> Hi Alexander,
>
> I am using intelhex v1.1 python script (Intel HEX file format reader and
> converter) developed by you for processing intel hex file.
> I use Python v2.5.4.
>
> I observed an issue with the script’s tobinstr() function. This function
> internally calls tobinarry(), and within tobinarry(), xrange() python api
> is used.
> I think xrange() function does not work for large integers. When I
> called tobinstr() with large integers as arguments,
> the exception ‘OverflowError: long int too large to convert to int’ was
> raised.
>
> Following is my code snippet:
> Ranges = [(2684625744L, 2684625749L)]
> Data = ''
> for Start, End in Ranges:
> Data += Hex.tobinstr(start=Start, end=End)
> print Data
>
> I checked with the latest version 1.5 of the intel hex script, but found
> that it too uses xrange() (inside _tobinarray_really()).
>
> It would be great if you could provide some details on this issue and a
> solution.
>
> Thanks,
> Dayasagar Patil
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/intelhex/+bug/1408934/+subscriptions
>

Changed in intelhex:
milestone: 1.5.1 → none
Revision history for this message
Xavi (xaviertisaire) wrote :

Another option, just to avoid breaking with long numbers it and keep
performance with short numbers would be:
        try:
            for i in xrange(start, end+1):
                bin.append(self._buf.get(i, pad))
        except:
            for i in lrange(start, end+1):
                bin.append(self._buf.get(i, pad))
        return bin
in the end lrange performance should be improved, but I think this is a
good compromise until then.

Xavier Tisaire
+436604851979
<email address hidden>

Warning: This e-mail is privileged, confidential and contains private
information. Any reading, retention, distribution or copying of this
communication by any person other than its intended recipient is prohibited.

On 1 April 2015 at 15:52, Alexander Belchenko <<email address hidden>
> wrote:

> ** Changed in: intelhex
> Milestone: 1.5.1 => None
>
> --
> You received this bug notification because you are subscribed to a
> duplicate bug report (1432704).
> https://bugs.launchpad.net/bugs/1408934
>
> Title:
> Problem with big int addresses
>
> Status in IntelHex files manipulating:
> Confirmed
>
> Bug description:
> Reported by e-mail (Dayasagar Patil)
>
> Hi Alexander,
>
> I am using intelhex v1.1 python script (Intel HEX file format reader and
> converter) developed by you for processing intel hex file.
> I use Python v2.5.4.
>
> I observed an issue with the script’s tobinstr() function. This function
> internally calls tobinarry(), and within tobinarry(), xrange() python api
> is used.
> I think xrange() function does not work for large integers. When I
> called tobinstr() with large integers as arguments,
> the exception ‘OverflowError: long int too large to convert to int’ was
> raised.
>
> Following is my code snippet:
> Ranges = [(2684625744L, 2684625749L)]
> Data = ''
> for Start, End in Ranges:
> Data += Hex.tobinstr(start=Start, end=End)
> print Data
>
> I checked with the latest version 1.5 of the intel hex script, but found
> that it too uses xrange() (inside _tobinarray_really()).
>
> It would be great if you could provide some details on this issue and a
> solution.
>
> Thanks,
> Dayasagar Patil
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/intelhex/+bug/1408934/+subscriptions
>

Revision history for this message
Alexander Belchenko (bialix) wrote :

It's trivial task to implement required address iterator without using
external libs. I'm going to fix it.

Changed in intelhex:
milestone: none → 2.0
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.