emrtd: Fix problem with certain reads being incorrect

This commit is contained in:
Ave but on a massive iMac 2021-04-26 12:02:50 +03:00
parent 20ca241816
commit a20f3afad2

View file

@ -1207,13 +1207,13 @@ static void emrtd_print_legal_sex(char *legal_sex) {
static int emrtd_mrz_determine_length(char *mrz, int offset, int max_length) {
int i;
for (i = max_length - 1; i >= 0; i--) {
if (mrz[offset + i] != '<') {
break;
for (i = max_length; i >= 1; i--) {
if (mrz[offset + i - 1] != '<') {
return i;
}
}
// if not found, it will return -1
return i;
return 0;
}
static int emrtd_mrz_determine_separator(char *mrz, int offset, int max_length) {
@ -1237,14 +1237,11 @@ static void emrtd_mrz_replace_pad(char *data, int datalen, char newchar) {
static void emrtd_print_optional_elements(char *mrz, int offset, int length, bool verify_check_digit) {
int i = emrtd_mrz_determine_length(mrz, offset, length);
if (i == -1) {
if (i == 0) {
return;
}
// Only print optional elements if they're available
if (i != 0) {
PrintAndLogEx(SUCCESS, "Optional elements.....: " _YELLOW_("%.*s"), i, mrz + offset);
}
PrintAndLogEx(SUCCESS, "Optional elements.....: " _YELLOW_("%.*s"), i, mrz + offset);
if (verify_check_digit && !emrtd_mrz_verify_check_digit(mrz, offset, length)) {
PrintAndLogEx(SUCCESS, _RED_("Optional element check digit is invalid."));
@ -1253,7 +1250,7 @@ static void emrtd_print_optional_elements(char *mrz, int offset, int length, boo
static void emrtd_print_document_number(char *mrz, int offset) {
int i = emrtd_mrz_determine_length(mrz, offset, 9);
if (i == -1) {
if (i == 0) {
return;
}
@ -1267,7 +1264,7 @@ static void emrtd_print_document_number(char *mrz, int offset) {
static void emrtd_print_name(char *mrz, int offset, int max_length, bool localized) {
char final_name[100] = { 0x00 };
int namelen = emrtd_mrz_determine_length(mrz, offset, max_length);
if (namelen == -1) {
if (namelen == 0) {
return;
}
int sep = emrtd_mrz_determine_separator(mrz, offset, namelen);