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

coders/pnm: Handle write failures #2081

Closed

Commits on May 31, 2020

  1. WIP: blob-private.h: add CheckWriteBlob*

    TODO:
    
    - Get rid of perror()
    - Pick proper function name for each macro (not literal WriteBlob*)
    MerlijnWajer committed May 31, 2020
    Copy the full SHA
    af038bf View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    7f1cb9e View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    1551c8a View commit details
    Browse the repository at this point in the history
  4. coders/pnm: return status in WritePNMImage

    Previously the code would always just return MagickTrue, even if it had
    just inferred that the processing failed. This is required for more
    elegant error handling throughout the function, such as checks on the
    WriteBlob() calls, where the return value is currently being ignored.
    
    Upon WriteBlob errors, we can then set the status to MagickFalse, and
    break.
    MerlijnWajer committed May 31, 2020
    Copy the full SHA
    9954f58 View commit details
    Browse the repository at this point in the history
  5. coders/pnm: stop on WriteBlob failures

    In WritePNMImage, when converting to a PNM image, the result of the
    WriteBlob calls is not checked, and instead ignored explicitly by
    '(void)' in front of it. This means that ImageMagick return success on
    images that get truncated when write(2) fails with ENOSPC.
    
    Evident by this sequence:
    
        $ ls -lsh /tmp/0009-1-small.png
        20M -rw-r--r-- 1 merlijn merlijn 20M May 25 23:59 /tmp/0009-1-small.png
        $ sudo mkdir /mnt/test
        $ sudo mount -t tmpfs none -o size=1G /mnt/test/
        $ df -h /mnt/test/
        Filesystem      Size  Used Avail Use% Mounted on
        none            5.0M     0  5.0M   0% /mnt/test
        $ convert /tmp/0009-1-small.png /mnt/test/0009.pnm
        $ echo $?
        0
        $ ls -lsh /mnt/test/0009.pnm
        5.0M -rw-r--r-- 1 merlijn merlijn 5.0M May 31 11:42 /mnt/test/0009.pnm
    
    Failure is evident with strace:
    
        write(5, "\373\372\367\373\371\367\372\370\365\372\370\364\372\370\364\372\371\366\372\367\363\363\355\346\351\344\327\370\363\356\372\370"..., 8192) = -1 ENOSPC (No space left on device)
    
    MagickCore/blob.c handles these errors nicely, but the callers of
    WriteBlob should still check the actual amount of written bytes.
    Since MagickCore/blob.c already handles EINTR for them, the checks are
    simple. This commit only fixes up the PNM image writing, but similar
    issues remain throughout the file.
    MerlijnWajer committed May 31, 2020
    Copy the full SHA
    577130d View commit details
    Browse the repository at this point in the history
  6. Copy the full SHA
    e300b20 View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    44a74ec View commit details
    Browse the repository at this point in the history