Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return early when packing zero length fields #149

Merged
merged 4 commits into from
Dec 3, 2021

Conversation

Dakinola892
Copy link
Contributor

Currently, composite fields will error when they try and pack zero length fields, a situation which arises when not all subfields in a composite (w/out id tags) are present.

The problem occurs when call .Pack() on individual fields, non populated fields would try and encode a zero length buffer and return an error - instead, now the field types will simply return an empty buffer and not error.

This will allows the packing of composite fields with non-populated subfields that fall outside of the composite prefix length.

Copy link
Member

@wadearnold wadearnold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contributions!

err := composite.SetData(data)
require.NoError(t, err)

// Subfield 4 & 5 falls outside of the bounds of the 3 byte limit imposed
Copy link
Contributor

@alovak alovak Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure I understand this bit of the PR. How does the early return help with fields that fall outside of the bounds? Also, where 3 byte limit prefix is? Is it because of ebcdic1047? Sorry for the dumb questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this probably wasn't explained the best by me - the motivation behind this PR was to allow length-prefixed composites that with non-tagged subfields to be parsed only up to the specified length, so that non-populated subfields in the composite could be ignored without erroring/panicking.

The problem with the current implementation is when trying to parse a composite without tagged subfields, Composite loops through all the subfield IDs in the spec regardless and errors when it tried to unpack a zero-length data buffer for a subfield not included in the data.

A possible fix would have been to just add check to Composite to stop parsing when we'd read >= the length of the data, but this caused an issue where errors weren't being accurately reported for invalid length data that was too long (i.e the spec only allows 4 bytes but 7 bytes were provided, it would stop reading after >= 4 bytes, so it wouldn't accurately highlight the issue with the combined length of the subfields).

So now I attempted to get the desired result by focusing on not panicking when attempting to unpack zero-length data fields.

Copy link
Contributor Author

@Dakinola892 Dakinola892 Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original example, I was referring to the '03' prefix when mentioning the 3 byte limit (i.e. [03 | 102] -> [length prefix | data]), but I've updated it the most recent commit to hopefully make it clearer

@codecov-commenter
Copy link

Codecov Report

Merging #149 (f6a1879) into master (38ed869) will decrease coverage by 0.11%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
- Coverage   70.84%   70.73%   -0.12%     
==========================================
  Files          36       37       +1     
  Lines        1581     1616      +35     
==========================================
+ Hits         1120     1143      +23     
- Misses        298      304       +6     
- Partials      163      169       +6     
Impacted Files Coverage Δ
field/track1.go 68.68% <0.00%> (-1.42%) ⬇️
field/track2.go 68.42% <0.00%> (-1.48%) ⬇️
field/track3.go 62.02% <0.00%> (-1.62%) ⬇️
field/composite.go 87.20% <68.75%> (-1.75%) ⬇️
padding/right.go 75.00% <75.00%> (ø)
field/binary.go 58.82% <100.00%> (+4.27%) ⬆️
field/string.go 77.41% <100.00%> (+0.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38ed869...f6a1879. Read the comment docs.

@adamdecaf
Copy link
Member

adamdecaf commented Dec 3, 2021

I'm looking for an approval from @alovak before we merge. I've included this in https://github.com/moov-io/iso8583/commits/v0.8-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants