libcephfs allows calling ftruncate on a file open read-only
When calling ceph_ftruncate on an "fd" open read only, using the O_RDONLY flag, libcephfs does not return and error and instead truncates the file. Compare this to the typical libc/linux ftruncate call which will return an error when the fd is not open for writing.
To reproduce I am attaching a simple c file that first "touches" the file (to ensure it exists) and then opens it read only and then demonstrates that truncate "succeeds" but a subsequent write fails. In comparison I attach a c file with system calls that demonstrates that ftruncate fails before reaching the write call.
I originally discovered this issue while wrapping APIs for go-ceph, but wrote the C versions to ensure this issue was, in fact, present in the libcephs layer.
Please let me know if I can provide any other information.