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

Fix #298, fix infinite loop when gz file is truncated #367

Merged
merged 1 commit into from
Oct 23, 2019
Merged

Fix #298, fix infinite loop when gz file is truncated #367

merged 1 commit into from
Oct 23, 2019

Conversation

avan989
Copy link
Contributor

@avan989 avan989 commented Oct 7, 2019

Describe the contribution
Fix issue #298, when cfe_fs_decompress goes into infinite loop when gz file is truncated.

Fix #298

Testing performed

  1. Build
  2. Pass in truncated file as parameter to cfe_fs_decompress.
    corgi2.jpg.gz
  3. Verify the return status:
STATUS CODE = -973078518
  1. Gzip good file
    66239143-f6736880-e6ad-11e9-98ac-ce321d6d495a

  2. Pass as parameter and verify output.

System(s) tested on:

  • Hardware
  • Ubuntu 18.04.03
  • cFE 6.7.0

Contributor Info
Anh Van, NASA Goddard

Community contributors
You must attach a signed CLA (required for acceptance) or reference one already submitted

@jphickey
Copy link
Contributor

jphickey commented Oct 8, 2019

Has this been confirmed to correctly handle a NON-truncated file?

@jphickey
Copy link
Contributor

jphickey commented Oct 8, 2019

Another general comment, if we are touching this code I would like to see a couple more changes.

The checks of len in the function should all be simplified to be just:

At line 287:

if (len <= 0) break;

And At line 294:

if (State->insize == 0 || len < 0) 
...

Rather than specifically testing for OS_ERROR only. Any negative value constitutes an error, and it will corrupt the state if not caught (i.e. insize could go negative).

Also note that the EOF macro is not defined by OSAL nor defined anywhere else in CFE. It just happens to not trigger a compiler error because it must be getting the value implicitly via stdio.h , and probably has the value -1. It might be clearer/better to just use -1 here.

@skliper
Copy link
Contributor

skliper commented Oct 8, 2019

Preference is to avoid "magic numbers" like -1. Is there an OSAL/CFE define that is appropriate?

@jphickey
Copy link
Contributor

jphickey commented Oct 8, 2019

Preference is to avoid "magic numbers" like -1. Is there an OSAL/CFE define that is appropriate?

Not particularly. The function is supposed to return the first character in the buffer, but in this case the buffer is empty, so there is nothing to return.

Another reasonable option might be the NUL char (0). But that just as magic as -1. Returning 0 won't corrupt the shift register that the values go into, whereas -1 does.

Either way though, this decompress code still violates coding standards in every conceivable way. I only mention it because it might cause a compile failure if things change and EOF no longer happens to be defined. Same with the length check (testing <= 0 vs. testing a specific value).

The real fix for this should be done in #291

@skliper
Copy link
Contributor

skliper commented Oct 9, 2019

Either way though, this decompress code still violates coding standards in every conceivable way. I only mention it because it might cause a compile failure if things change and EOF no longer happens to be defined. Same with the length check (testing <= 0 vs. testing a specific value).

Understood. Let's fix the <=0 now. The EOF builds today and the "-1" solution isn't acceptable, so lets just leave as is for now. Or if you really want to, feel free to propose a solution that doesn't include the use of a "magic number" (create an appropriate #define, identify an appropriate one that already exists, or whatever). But I don't think the EOF change is worth our time right now due to #291.

The real fix for this should be done in #291

Agreed, which is why I'm OK with leaving the EOF as-is, but I'd like to get this fix in first.

@skliper
Copy link
Contributor

skliper commented Oct 9, 2019

Since it's all local to cfe_fs_decompress.c, why not just:

#define CFE_FS_EOF -1

or something? and change EOF to CFE_FS_EOF?

@avan989
Copy link
Contributor Author

avan989 commented Oct 9, 2019

update checks of lens. Tested with truncated file and non truncated file. Truncated file return

STATUS CODE = -973078518

Non-truncated file decompress and return images.

testResult

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

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

Looks good.

@skliper skliper added the CCB:Approved Indicates code review and approval by community CCB label Oct 10, 2019
@skliper skliper added this to the 6.8.0 milestone Oct 10, 2019
jphickey added a commit that referenced this pull request Oct 11, 2019
Merge branches 'p27', 'p367' and 'p369' for integration
@jphickey jphickey merged commit b7e1307 into nasa:master Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:Approved Indicates code review and approval by community CCB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CFE_FS_Decompress infinite loop on truncated gzip file
3 participants