Skip to content
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

comparing le + offset to file size in processReadBinary #16

Closed
wants to merge 2 commits into from

Conversation

hfmanson
Copy link
Contributor

@hfmanson hfmanson commented Apr 6, 2018

The comparison should use normal integers since le+offset can be greater than 32767. The difference can be cast back to a short.

@hfmanson hfmanson changed the title Bug fix Bug fix while comparing le + offset to filesize Apr 6, 2018
@hfmanson hfmanson changed the title Bug fix while comparing le + offset to filesize comparing le + offset to file size Apr 6, 2018
@hfmanson hfmanson changed the title comparing le + offset to file size comparing le + offset to file size in processReadBinar Apr 6, 2018
@hfmanson hfmanson changed the title comparing le + offset to file size in processReadBinar comparing le + offset to file size in processReadBinary Apr 6, 2018
@philipWendland
Copy link
Owner

philipWendland commented Apr 6, 2018

Hi,
all smart cards that I know of only support 16 bit integers (signed, because of Java). You can not have files larger than 16 KiB.

Your pull request does not compile:

[cap] error: line 704: net.pwendland.javacard.pki.isoapplet.IsoFileSystem: unsupported int type of intermediate value, must cast intermediate value to type short or byte.

@philipWendland philipWendland self-requested a review April 6, 2018 21:48
@philipWendland philipWendland self-assigned this Apr 6, 2018
@hfmanson
Copy link
Contributor Author

hfmanson commented Apr 7, 2018

Dear philip,

le will be 0x7FFF because the applet implements the ExtendedLength interface

        short le = apdu.setOutgoing();

The problem occurs when reading with a non 0 offset, e.g. 0x100, :
in the comparison:

if (le+offset >= fileData.length) {
    le = (short)(fileData.length - offset);
}

Then le+offset is 0x7fff + 0x100 == 0x80FF. When this result is cast to a short it results in a negative number.

Which javac are you using in your project? I converted IsoApplet to Netbeans 8.2 where I don't get a compile error.

@hfmanson
Copy link
Contributor Author

hfmanson commented Apr 8, 2018

With this updated code the intermediate value will always be short

@philipWendland
Copy link
Owner

Squashed, rebased, reworded and applied in 4ec7308.

Can I ask what the real-word use case for this was? I cannot imagine why this change is relevant in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants