Tochemey / NetCore8583

NetCore8583 is a library that helps parse/read and generate ISO 8583 messages for .NET Core
MIT License
33 stars 21 forks source link

Can't parse message if the field 125 is in parsing template while it's not in the message #15

Closed codedius closed 11 months ago

codedius commented 2 years ago

Hi @Tochemey !

Trying to use your lib with the UK FasterPayments (FPS) integration and there's might be an issue:

Message: 9804000001020000000089118000000000000000007 (Type 9804, ASCII, BCD bitmap)

FPS has their own implemetation of the ISO8583 and fields of the message above are:

The problem with the 125 field that is conditional and it might be in the message (with the secondary bitmap) but might be not (therefore secondary bitmap is also absent). So the description of the lib says:

A message does not need to contain all the fields specified in a parsing template, but a parsing template must contain all the fields specified in the bitmap of a message, or the MessageFactory won't be able to parse it because it has no way of knowing how it should parse that field (and also all subsequent fields).

And it works perfectly with fields up to 64 even though they are not presented in the message. But once I have field 125 in my parsing template and it is not presented in the message AND secondary bitmap is not presented as well the parsing crashes with the message in my case:

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') Actual value was 124.'

If I remove 125 from parsing template, then it works.

What I want is be able to put any conditional fields in the parsing template regardless of bitmap they are belong and get correct message with posibility to check whether conditional fields parsed or not. Looks like the lib relies on the bitmaps presented, so If there are no field AND no bitmap it crashes.

Seems like it's MessageFactory.cs, Line 588: if (bs.Get(i - 1))

Tochemey commented 2 years ago

@codedius Thanks for reporting this. At the moment I really don't have the bandwidth to look into this. I will be glad if you can open a PR to address it. Bear in mind that the fix should cater for a general use not for your use case. Thanks

Tochemey commented 1 year ago

@codedius I will have to close this issue because there is no activity. Feel free to reopen it.

Tochemey commented 1 year ago

@codedius I would like to know whether you have an opportunity to fix this. I am reopening the issue.