moov-io / iso8583

A golang implementation to marshal and unmarshal iso8583 message.
https://moov.io
Apache License 2.0
349 stars 104 forks source link

JSON marshaling panics on specs with empty extended bitmap #86

Closed krishishah closed 3 years ago

krishishah commented 3 years ago

The official ISO8583 spec consists of an extended bitmap in DE 65. In practice, this is left empty in the vast majority of the use cases. JSON marshaling panics on a nil pointer reference on specs with this field defined.

In particular, it panics here because the underlying utils.Bitmap is nil at runtime:

 func (f *Bitmap) Bytes() ([]byte, error) {                                                                                                                                                                                                                                                                                                                                      
     return f.bitmap.Bytes(), nil                                                                                                                                                              
 } 

Adding a nil check before referencing the underlying bitmap fixes this issue.

Does this library have support for extended bitmaps?

alovak commented 3 years ago

@krishishah bitmap dynamically reads all bitmaps from the message as following:

I see that DE 65 is 1 bit (in some specs) but not sure what's the value of it.

May I ask you to share your code (you can do this privately) so I can better understand why it panics?

alovak commented 3 years ago

@krishishah I've fixed a tiny issue related to JSON Marshalling here https://github.com/moov-io/iso8583/pull/87

maybe it will fix your issue? :)

krishishah commented 3 years ago

@alovak it's actually 8 bytes on the official ISO spec and for the scheme we are integrating against as well. It indicates the presence of a 3rd segment of the message.

The scheme we are integrating against always has it populated as 0 but the only code change we made was to add it to the message spec as a Bitmap field against index 65.

Your change fixed the issue, great work!