Skip to content

Bad checksum not being overwritten on call to "writeto" #5902

Description

@mohanagr

Astropy v2.0

Test files used:

  • io/fits/tests/data/test0.fits - ImageHDU extensions
  • io/fits/tests/data/checksum.fits - A BinTableHDU extension

While working on #5874 I came across this :-

  • I modified the CHECKSUM header of checksum.fits and added CHECKSUM to test0.fits and modified it's CHECKSUM header too. (i.e. 16 letter long garbage value).
  • Opened and overwrote both the files. Correct CHECKSUMs were written only for test0.fits

This corrected the Garbage checksums.

>>> hlist = fits.open('./tests/data/test0.fits')
>>> hlist.writeto('./tests/data/test0.fits', checksum='standard', overwrite=True, output_verify='ignore')
>>> hlist.close()

and this didn't.

>>> hlist = fits.open('./tests/data/checksum.fits')
>>> hlist.writeto('./tests/data/checksum.fits', checksum='standard', overwrite=True, output_verify='ignore')
>>> hlist.close()

The above one works if something like -
>>> hlist = fits.open('./tests/data/checksum.fits', checksum=True) is used.

Is this because of different types of extensions that are present?

On digging a bit this is happening because hdu._header._modified is False for checksum.fits case.
https://github.com/astropy/astropy/blob/master/astropy/io/fits/hdu/base.py#L522

Activity

  1. mohanagr commented on Apr 28, 2017

    @mohanagr
    ContributorAuthor

    @pllim @Cadair @saimn Any updates for this?
    P.S. Apologies for tagging you all. Don't quite know who maintains what.

  2. pllim commented on Apr 28, 2017

    @pllim
    Member

    Trying my luck on additional @embray and @MSeifert04 . cadair is not involved in FITS and I have little to say about this topic.

  3. MSeifert04 commented on Apr 28, 2017

    @MSeifert04
    Contributor

    What would be the correct behaviour here? I mean output_verify is False and the checksum parameter was "sort of" True. However the checksum parameter only says "When True adds both DATASUM and CHECKSUM cards to the headers of all HDU’s written to the file.", does that mean it should always overwrite the existing DATASUM and CHECKSUM or just add them if not present?

    I mean the test case is a bit theoretical: If you explicitly garbage the CHECKSUM and don't check it when reading the file what's the point about "correcting" it when writing the file again?

    The documentation of checksum in fits.open is this:

    If True, verifies that both DATASUM and CHECKSUM card values (when present in the HDU header) match the header and data of all HDU’s in the file. Updates to a file that already has a checksum will preserve and update the existing checksums unless this argument is given a value of ‘remove’, in which case the CHECKSUM and DATASUM values are not checked, and are removed when saving changes to the file.

    That actually means (in my opinion) that when you suspect a "garbage" checksum you should provide checksum='remove' when reading the file and checksum=True when writing it again.

  4. embray commented on May 3, 2017

    @embray
    Member

    I'd have to take a closer look, but it's a known (to me) issue that checksum handling is confusing. I believe there may already be some open tickets about this either here or in the old PyFITS repo. Which is not to say the behavior isn't deliberate. It's just confusing.

  5. embray commented on May 3, 2017

    @embray
    Member

    does that mean it should always overwrite the existing DATASUM and CHECKSUM or just add them if not present

    I think this means it should overwrite. DATASUM and CHECKSUM are two of those "special" header keywords that nobody should ever touch manually without very good reason to.

  6. mohanagr commented on May 3, 2017

    @mohanagr
    ContributorAuthor
  7. saimn commented on Sep 25, 2017

    @saimn
    Contributor

    Fixed by #6571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions