CF updates its destination file "in-place"

Open
#132 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
c
Domain
networking

Research direction

Start by tracing the CF receive path that opens the destination named in the Metadata PDU, then review the corner-case handling discussed in issue #131. The change is complete when incoming data is written to a temporary file and the original destination is replaced only after final CRC and size validation succeeds.

Written by the indexing model from the issue text.

Description

enhancement

The CF application, when receiving files, will open the destination file as indicated in the Metadata PDU and immediately start writing data to it, thereby overwriting any data that was previously in the file at that position.

This can be dangerous, because the file transfer may not ultimately succeed. For instance, CRC errors may occur, or part of the transfer might get lost. But once data has been clobbered, there is no way to "undo" and restore the original data -- its gone. So now the user has a situation where neither the new file nor the original file are valid - the file is just corrupt now.

It is often desirable to write data to a temporary file first, let the transfer run to completion (storing ALL data in the temporary file), and then rename the file to its final/correct filename only after the final CRC and size checks have passed and the data is known to be good (or at least to the extent that CF can verify it).

In fact, this is the only way to safely update application binary object (.so files) on many targets, since the text/rodata memory pages may be mmap'ed directly to the file on disk. If these are updated in place, and the file is an actively-running application, then the running code will immediately "see" the modifications, and likely crash/segfault depending on what it was doing at the time.

Recommendation here is to ALWAYS use a temporary file to store incoming data, never overwrite existing files until final validations have occurred. This will also avoid some of the special logic that only handled corner cases (see issue #131) by making that more the norm than the exception.

Dominant language
C
Stars
123
Forks
82
Avg merge
2d 22h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nasa/CF

All issues in nasa/CF

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.