-
Notifications
You must be signed in to change notification settings - Fork 31
Updating existing files in an ADF image #30
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
Comments
Hi, nice idea!
|
About cve, I do not know how it is been fixed by Debian, maybe compiler memory safety options |
Hi Laurent, what did you mean by Debian CVEs? There haven't been any since 2016.
|
How is it fixed? Code patch or makefile patch? |
Cve Listed in readme.md |
|
Thanks for reminding this Stuart! |
I briefly looked at writing files, it seems to me that:
So basically at the moment writing files seems to work properly only if a new file is created, and immediately (without closing and reopening) written and closed. (write support should rather be considered experimental until fixed...) Some of these could be caused eg. by my changes in the seek code - but since there was no test how could I know... Concerning the 2nd point - does anyone know how exactly such an empty file looks like on Amiga filesystem? I mean, if it is a 0-length file does it have any data blocks allocated (as current code seems to expect) or there is only a file header block? And if there is only file header block, how this lack of data blocks is (or should be) indicated in file header block ( |
I totally agree about limitations of current code. |
Hummm, is adflib or amigados vulnerable to this? https://twitter.com/David3141593/status/1639785897657769986 |
Almost every filesystem is "vulnerable" to you modifying a file (or even deleting it), and it being possible to recover all or part of the old file, because most filesystems do not blank out freed data blocks. It's desirable that they don't - faster, less disk wear, possible to recover files. But no, this is not a "vulnerability" as it's expected behaviour for filesystems. Whereas if you are cropping an image and saving it, it is a vulnerability that cropped parts of the image remain in the file. If someone wants to ensure their files are unrecoverable, even to forensic investigators, there are tools like If someone wants to create a disk image with nothing but the expected files, they should do their editing somewhere else, format a new disk and copy the files over. |
The root cause of the "acropalypse" is that Google copied the C idea of Then, some idiot at Google decided in Android 10 (released 2019) that "w" should not truncate any more, and you have to write "wt" if you want the standard behaviour. "w" was standard since Android was created, and is the familiar standard in other languages like C and Python. BREAKING. API. CHANGE. And they didn't document it until 2021, when someone filed a bug to them noting the unannounced change. UNDOCUMENTED. BREAKING. API. CHANGE. Possibly every Android app, ever, is affected when running on Android 10 or later. And one such app affected is Google's flagship screenshot/cropping app! Yes, even Google didn't know that Google silently broke their API. So perhaps to avoid this in ADFLib, write in the API documentation that |
To create an empty file, there is a file header block allocated, but there are no data blocks allocated. The file header looks like this:
When adfWriteFile() is called, it might require extending the file to use more datablocks:
I haven't check the Amiga code for extension blocks, so I don't know if it's a better strategy to allocate blocks in a row like HEADER EXTENSION EXTENSION DATA DATA DATA DATA .. or like HEADER DATA DATA DATA EXTENSION DATA DATA DATA EXTENSION DATA DATA DATA ... When adfCloseFile() is called, let's assume that adfOpenFile(..., "w") means the standard C behaviour that you truncate the file to how many bytes were written. If what was written is shorter than the file's original length, this means truncating the file:
|
Thanks for the info. So far any file truncation is not implemented (even in the update I am preparing). But it seems like possibly next step to do so your info will be helpful in that. |
... was that the command line
... is still a crashing bug, even today in master and in https://github.com/t-w/ADFlib/tree/devel adfGetCacheEntry() in src/adf_cache.c copies a cache block entry.
It then passes these lengths direct to memcpy(). The example file attached to the debian bug has a cache entry with name length -117 and comment length -1, e.g. 0xFFFFFFFF when cast to size_t
|
@kyz, thanks for the info about the security bug you mention above (in This issue is focused rather on making the write support working. So please, go ahead and create a separated issue (as for other matters, if there are such). It will be easier to check topic by topic. |
@kyz, concerning Implementing full POSIX-like interface for opening file... seems overcomplicated. For pure filesystem interface, it may make more sense (to give client code a high level interface). For a library like ADFlib, which gives a rather low-level interface to the ADF devices/volumes/files, I would rather propose to keep it as simple as possible, at least until all needed basic things are implemented (for now, truncate is missing, so eg. "w" in POSIX way cannot be added). |
I agree it's a separate issue, I was just responding to Laurent's comment As the bug already has a Debian bug entry, I don't see the need for duplicating it in Github, so I simply added a pull request referencing the Debian bug, and with a fix: #35 |
A filesystem that can "update files" should be able to truncate them, extend them, seek within them and read and write parts of them. But I also recognize that's a lot of work, and you've already done a huge amount. It's OK if file update support is only partially implemented. APIs can return error codes where specific operations aren't implemented yet My comments here for the future, while also wearing a security hat. What is good API design? It is when the API does what you expect and does not surprise you The aCropalypse bug, where millions of people might have overshared sensitive information for years, is all due to a change of API design that went against expectations and surprised programmers It's my argument that any programmer on the planet, who has never seen ADFLib, but has seen C, Python, etc., when they want to update files in an ADF image, they will see look at the docs, they will see, adfOpenFile, adfCloseFile, adfReadFile, adfWriteFile, adfFileSeek, and they will expect these functions work like fopen, fclose, fread, fwrite, fseek from C... or that they work like open, close, read, write, seek from Unix... or that they work like CreateFile, CloseHandle, ReadFile, WriteFile, SetFilePointer from Win32... or that they work like Open, Close, Read, Write, Seek from AmigaDOS... When looking at adfOpenFile(), they will see it takes a string as an access mode. So they will immediately think that this works like fopen() in C. We shoudn't surprise them
The library can call its own functions to do that for the client. That's much simpler than finding bugs where the programmer has misunderstood the API because it goes against expectations I would recommend designing the API now, being happy it is coherent, and then filling in the implementation, rather than change the API to match the current state of implementation. And don't ask clients to work around missing implementation and then change the API later when it's implemented and break them again
Think about the future. If "w", which implies truncate, can't be done because the code's not there, ADFLib should allow only "r" (read-only) and "r+" (open for read and write) and return an error for any other mode. This would be the least surprising API and requires no extra code today, just coherent API design The alternative is that "w" means "truncate" everywhere, except ADFLib where it means "no truncate", for today, and then later when ADFLib gains the ability to truncate files, either we change "w" from "no truncate" to "truncate" (which is a breaking API change), or we decide to keep ADFLib backwards-compatible with itself and remain unlike fopen() forever, perhaps adopting "wt" to mean what everyone else uses "w" to mean, and therefore the ADFLib API remains surprising and unexpected and a source of bugs due to mismatched developer expectations |
Yes, I suggest to keep adflib simple. Even for windows NTFS, you have a separate tool for data sanitisation : sdelete from sysinternals. R, w and a seems enough for adflib. Sdelete / secure delete could be offered as a separate cli tool, as well as undelete, but not via os like API |
@kyz, while you do have a point, the discussion about API design is a separated issue, while this issue is just about fixing/implementing a very basic functionality possibly within the existing API design, not about changing it. In the meantime, please have a look at #34 (test if possible), so that we can close that part and go on. The next things to do that I would foresee (rather than an extensive discussion about details to change in the API):
These are internals, not the external API (which can be discussed separately). |
This is done (eventually to improve, see TODO ). |
I have started working on write support for fuseadf and have just found out that the library does not support updating existing files in ADF image. The write support modes (for
adfOpenFile()
) are:This is probably not the simplest feature to implement but a pretty crucial one (eg. at the moment, there is no reasonable way to implement write support in a filesystem using ADFlib) so it would be good to add it.
The text was updated successfully, but these errors were encountered: