ZsBT/mrz-java

A MrzParserException is thrown when the dates in the MRZ are invalid (e.g 1999 September 35)

GoUpNorth opened this issue · 5 comments

I noticed that when we try to parse an MRZ in which either the date of birth or the date of expiry is invalid, then a MrzParserException is thrown and all the other parsed data are lost.

The exception message looks like this:
Failed to parse MRZ PASSPORT P<GBRUK<SPECIMEN<<ANGELA<ZOE<<<<<<<<<<<<<<<<
9250764733GBR8809417F2007162<<<<<<<<<<<<<<08 at 17-19,1: Failed to parse MRZ date: invalid day value 41: must be 1..31

It could be interesting to continue the parsing even if the dates are incorrect, and leave the integrator check if they are correct or not.

From what I saw in the code, the modifications would have to be made in the MrzParser and MrzDate classes.

Invalid MRZ examples:
"P<GBRUK<SPECIMEN<<ANGELA<ZOE<<<<<<<<<<<<<<<<"
"9250764733GBR8809417F2007162<<<<<<<<<<<<<<08" Invalid date of birth

"P<GBRUK<SPECIMEN<<ANGELA<ZOE<<<<<<<<<<<<<<<<"
"9250764733GBR8809117F2007462<<<<<<<<<<<<<<08" Invalid date of expiry

Regards,
P-A

ZsBT commented

Indeed invalid dates could be interesting, however this kind of error must be handled somehow.
I can imagine a custom exception class that can be caught.

Well my idea was not to stop the parsing if the dates are invalid. I was more thinking about adding a boolean flag in the MrzDate class, that would indicate if the date is valid or not. A bit like what you did in the MrzRecord class with the booleans corresponding to the different checksums validity.

ZsBT commented

I see. As MrzRecord already contains validity booleans, I think the validDateOfBirth and validExpirationDate should be also false when its MrzDate validity boolean is false.
Shall you have a working code, don't hesitate to send a pull request in this repo.

Ok I'll do that.

ZsBT commented

fixed with merged pull request #14 .