iso7816.c: allow file length stored in more than 2 bytes
as indicated in iso7816-4 chapter 7.4.3 table 10 Fixes #459
This commit is contained in:
parent
8b62221abc
commit
492ffe0fd7
|
@ -350,6 +350,7 @@ iso7816_process_fci(struct sc_card *card, struct sc_file *file,
|
|||
{
|
||||
struct sc_context *ctx = card->ctx;
|
||||
size_t taglen, len = buflen;
|
||||
int i;
|
||||
const unsigned char *tag = NULL, *p = buf;
|
||||
|
||||
sc_log(ctx, "processing FCI bytes");
|
||||
|
@ -359,17 +360,25 @@ iso7816_process_fci(struct sc_card *card, struct sc_file *file,
|
|||
sc_log(ctx, " file identifier: 0x%02X%02X", tag[0], tag[1]);
|
||||
}
|
||||
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
|
||||
if (tag == NULL) {
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
|
||||
}
|
||||
if (tag != NULL && taglen > 0 && taglen < 3) {
|
||||
file->size = tag[0];
|
||||
if (taglen == 2)
|
||||
file->size = (file->size << 8) + tag[1];
|
||||
sc_log(ctx, " bytes in file: %d", file->size);
|
||||
} else {
|
||||
/* determine the file size */
|
||||
/* try the tag 0x80 then the tag 0x81 */
|
||||
file->size = 0;
|
||||
for (i = 0x80; i <= 0x81; i++) {
|
||||
int size = 0;
|
||||
len = buflen;
|
||||
tag = sc_asn1_find_tag(ctx, p, len, i, &taglen);
|
||||
if (tag == NULL)
|
||||
continue;
|
||||
if (taglen == 0)
|
||||
continue;
|
||||
if (sc_asn1_decode_integer(tag, taglen, &size) < 0)
|
||||
continue;
|
||||
if (size <0)
|
||||
continue;
|
||||
|
||||
file->size = size;
|
||||
sc_log(ctx, " bytes in file: %d", file->size);
|
||||
break;
|
||||
}
|
||||
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
|
||||
|
|
Loading…
Reference in New Issue