New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in thread "main" java.lang.StringIndexOutOfBoundsException #349

Closed
iBotPeaches opened this Issue Mar 18, 2015 · 6 comments

Comments

Projects
None yet
1 participant
@iBotPeaches
Owner

iBotPeaches commented Mar 18, 2015

Original issue 238 created by ljb2005 on 2011-11-14T09:37:30.000Z:

What steps will reproduce the problem?
fed cmd with apktools d test.apk test,then exception message arose.

What is the expected output? What do you see instead?
It should produce smail files without any error.I saw exception,of course ,it wont rebuild a apk file from these files

What version of the product are you using? On what operating system?
apktool v1.4.1, Windows 7 Chinese edition,JRE 6u26

Please provide any additional information below.
test file included in the attach file
I: Baksmaling...
testI: Loading resource table...
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 33121
at java.lang.String.substring(Unknown Source)
at brut.androlib.res.decoder.StringBlock.getHTML(StringBlock.java:161)
at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:222)

    at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:177)

    at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:165

)
at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:130)
at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:10
5)
at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:315)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.jav
a:50)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.jav
a:43)
at brut.androlib.Androlib.getResTable(Androlib.java:44)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
at brut.apktool.Main.cmdDecode(Main.java:120)
at brut.apktool.Main.main(Main.java:57)

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #1 originally posted by Brut.alll on 2011-11-28T23:18:51.000Z:

<empty>

Owner

iBotPeaches commented Mar 18, 2015

Comment #1 originally posted by Brut.alll on 2011-11-28T23:18:51.000Z:

<empty>

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #2 originally posted by Brut.alll on 2011-11-28T23:23:42.000Z:

No, I was wrong ;-)

Owner

iBotPeaches commented Mar 18, 2015

Comment #2 originally posted by Brut.alll on 2011-11-28T23:23:42.000Z:

No, I was wrong ;-)

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #3 originally posted by naresh.mehta on 2011-11-30T15:02:09.000Z:

Hi,

I have been facing the same issue. I am using Windows XP 32-bit with apktoolv1.4.1. Whenever I run the command apktool d -d test.apk test, I get the following:

I: Baksmaling...
I: Loading resource table...
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 33121
at java.lang.String.substring(Unknown Source)
at brut.androlib.res.decoder.StringBlock.getHTML(StringBlock.java:161)
at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:222)

    at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:177)

    at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:165

)
at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:130)
at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:10
5)
at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:315)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.jav
a:50)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.jav
a:43)
at brut.androlib.Androlib.getResTable(Androlib.java:44)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
at brut.apktool.Main.cmdDecode(Main.java:120)
at brut.apktool.Main.main(Main.java:57)

Please fix this and thankyou for the excellent tool.

Owner

iBotPeaches commented Mar 18, 2015

Comment #3 originally posted by naresh.mehta on 2011-11-30T15:02:09.000Z:

Hi,

I have been facing the same issue. I am using Windows XP 32-bit with apktoolv1.4.1. Whenever I run the command apktool d -d test.apk test, I get the following:

I: Baksmaling...
I: Loading resource table...
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 33121
at java.lang.String.substring(Unknown Source)
at brut.androlib.res.decoder.StringBlock.getHTML(StringBlock.java:161)
at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:222)

    at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:177)

    at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:165

)
at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:130)
at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:10
5)
at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:315)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.jav
a:50)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.jav
a:43)
at brut.androlib.Androlib.getResTable(Androlib.java:44)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
at brut.apktool.Main.cmdDecode(Main.java:120)
at brut.apktool.Main.main(Main.java:57)

Please fix this and thankyou for the excellent tool.

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #4 originally posted by jgomezb on 2013-11-10T11:00:13.000Z:

Same problem here.

Owner

iBotPeaches commented Mar 18, 2015

Comment #4 originally posted by jgomezb on 2013-11-10T11:00:13.000Z:

Same problem here.

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #5 originally posted by connor.tumbleson on 2014-02-09T06:56:19.000Z:

These strings are exceeding the length of short with size values around 33590, etc.

There is a note in ResourcesTypes.cpp, which I caught during research

/**

  • Strings in UTF-16 format have length indicated by a length encoded in the
  • stored data. It is either 1 or 2 characters of length data. This allows a
  • maximum length of 0x7FFFFFF (2147483647 bytes), but if you're storing that
  • much data in a string, you're abusing them.
    *
  • If the high bit is set, then there are two characters or 4 bytes of length
  • data encoded. In that case, drop the high bit of the first character and
  • add it together with the next character.
    */

During execution of decode() -> readTable() -> readPackage() -> readType() -> readConfig() -> readEntry() -> readValue() -> getHTML()

We incorrectly assume without reading the note about the high set bit. This occurs in StringBlock.java, in function getShort(). The function is returning a short. So we need to create a newer function "decodeUtf16" or something and update this to above spec. I feel this bug is also the reason many applications that abuse string length are failing.

Owner

iBotPeaches commented Mar 18, 2015

Comment #5 originally posted by connor.tumbleson on 2014-02-09T06:56:19.000Z:

These strings are exceeding the length of short with size values around 33590, etc.

There is a note in ResourcesTypes.cpp, which I caught during research

/**

  • Strings in UTF-16 format have length indicated by a length encoded in the
  • stored data. It is either 1 or 2 characters of length data. This allows a
  • maximum length of 0x7FFFFFF (2147483647 bytes), but if you're storing that
  • much data in a string, you're abusing them.
    *
  • If the high bit is set, then there are two characters or 4 bytes of length
  • data encoded. In that case, drop the high bit of the first character and
  • add it together with the next character.
    */

During execution of decode() -> readTable() -> readPackage() -> readType() -> readConfig() -> readEntry() -> readValue() -> getHTML()

We incorrectly assume without reading the note about the high set bit. This occurs in StringBlock.java, in function getShort(). The function is returning a short. So we need to create a newer function "decodeUtf16" or something and update this to above spec. I feel this bug is also the reason many applications that abuse string length are failing.

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Mar 18, 2015

Owner

Comment #6 originally posted by connor.tumbleson on 2014-02-10T01:25:37.000Z:

ca314b9

Fixed. Will be in next beta.

Owner

iBotPeaches commented Mar 18, 2015

Comment #6 originally posted by connor.tumbleson on 2014-02-10T01:25:37.000Z:

ca314b9

Fixed. Will be in next beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment