Block and undo files are open by OpenDiskFile, there is a read only parameter. But in fopen function call, “rb+” mode is read-or-write mode, read-only paramter is ignored, so it always open for write. https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp#L3467
from fopen man:
r+ or rb+ or r+b
Open file for update (reading and writing).
w+ or wb+ or w+b
Truncate to zero length or create file for update.
Is this a bug or feature?
(old times in readonly open, fopen is called by “rb” mode: https://github.com/bitcoin/bitcoin/commit/5382bcf8cd23c36a435c29080770a79b5e28af42#diff-e8db9b851adc2422aadfffca88f14c91L635)