Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:15:09+00:00 2026-06-01T09:15:09+00:00

I am running the following code on ubuntu 11.10, python 2.7.2+. import urllib import

  • 0

I am running the following code on ubuntu 11.10, python 2.7.2+.

import urllib
import Image
import StringIO
source = '/home/cah/Downloads/evil2.gfx'
dataFile = open(source, 'rb').read()
slicedFile1 = StringIO.StringIO(dataFile[::5])
slicedFile2 = StringIO.StringIO(dataFile[1::5])
slicedFile3 = StringIO.StringIO(dataFile[2::5])
slicedFile4 = StringIO.StringIO(dataFile[3::5])
jpgimage1 = Image.open(slicedFile1)
jpgimage1.save('/home/cah/Documents/pychallenge12.1.jpg')
pngimage1 = Image.open(slicedFile2)
pngimage1.save('/home/cah/Documents/pychallenge12.2.png')
gifimage1 = Image.open(slicedFile3)
gifimage1.save('/home/cah/Documents/pychallenge12.3.gif')
pngimage2 = Image.open(slicedFile4)
pngimage2.save('/home/cah/Documents/pychallenge12.4.png')

in essence i’m taking a .bin file that has hex code for several image files jumbled
like 123451234512345… and clumping together then saving. The problem is i’m getting the following error:

File "/usr/lib/python2.7/dist-packages/PIL/PngImagePlugin.py", line 96, in read
len = i32(s)
File "/usr/lib/python2.7/dist-packages/PIL/PngImagePlugin.py", line 44, in i32
return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24)
IndexError: string index out of range

i found the PngImagePlugin.py and I looked at what it had:

def i32(c):

    return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) (line 44)

"Fetch a new chunk. Returns header information."

    if self.queue:
        cid, pos, len = self.queue[-1]
        del self.queue[-1]
        self.fp.seek(pos)
    else:
        s = self.fp.read(8)
        cid = s[4:]
        pos = self.fp.tell()
        len = i32(s) (lines 88-96)

i would try tinkering, but I’m afraid I’ll screw up png and PIL, which have been erksome to get working.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:15:10+00:00Added an answer on June 1, 2026 at 9:15 am

    It would appear that len(s) < 4 at this stage

    len = i32(s)
    

    Which means that

    s = self.fp.read(8)
    

    isn’t reading the whole 4 bytes

    probably the data in the fp you are passing isn’t making sense to the image decoder.

    Double check that you are slicing correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got running sample python code which is fine in Ubuntu desktop: import dbus,
Running GNU Emacs 22.2.1 on Ubuntu 9.04. When editing python code in emacs, if
I'm running Python 2.6.6 on Ubuntu 10.10. I understand that we can import a
I am running the following code on a 64-bit Ubuntu box with 18 GB
When compiling the following C code with ndk-build in Terminal (I'm running Ubuntu): #include
I'm running the following code on Ubuntu 10.10, using OpenJDK 1.6.0_18: package mypkg; public
Running the following code, I get a StackOverflowError at the getPackage() line. How can
Running the following code, I get an exception: using (var client = new Pop3Client())
When running the following code I get no output but I cannot work out
I'm running the following code to get a random entry from a dictionary: SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.