Anonymous | Login | 2024-10-14 23:43 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||||||||
0001830 | [1003.1(2016/18)/Issue7+TC2] System Interfaces | Editorial | Enhancement Request | 2024-05-03 06:55 | 2024-05-20 16:10 | ||||||||
Reporter | lacos | View Status | public | ||||||||||
Assigned To | |||||||||||||
Priority | normal | Resolution | Accepted As Marked | ||||||||||
Status | Resolved | ||||||||||||
Name | László Érsek | ||||||||||||
Organization | |||||||||||||
User Reference | |||||||||||||
Section | pwrite, write | ||||||||||||
Page Number | ? | ||||||||||||
Line Number | ? | ||||||||||||
Interp Status | --- | ||||||||||||
Final Accepted Text | Note: 0006786 | ||||||||||||
Summary | 0001830: off-by-one error regarding offset maximum | ||||||||||||
Description |
(Sorry for not providing page and line numbers; I've not been following POSIX development for a good while, and don't remember where I could download a PDF version.) The open() specification contains: "The largest value that can be represented correctly in an object of type off_t shall be established as the offset maximum in the open file description." The write() / pwrite() spec states the following, *consistently* with the open() spec: """ [EFBIG] The file is a regular file, nbyte is greater than 0, and the starting position is greater than or equal to the offset maximum established in the open file description associated with fildes. """ However, the write() / pwrite() spec also states the following, *inconsistently* with the above references: "For regular files, no data transfer shall occur past the offset maximum established in the open file description associated with fildes." This last statement is not strict enough; a data transfer even precisely *at* the offset maximum, not just past it, should not occur. Otherwise, the resultant offset will not be representable in off_t. Footnote 1: for simplicity, assume that off_t is identical to int8_t; in that case, the off_t maximum, hence the offset maximum, is 127. If we allowed lseek(fd, 127, SEEK_SET); write(fd, "X", 1); to succeed, then the next call to lseek(fd, 0, SEEK_CUR); would have to fail with -1/EOVERFLOW. The EFBIG description in write() actually forbids the above write() from succeeding -- correctly so --, however the "no data transfer shall occur past the offset maximum" language would permit this write() to succeed (because the data transfer would occur precisely *at* the offset maximum), and that's what's wrong.) Footnote 2: this is an interesting difference from pointer arithmetic in the C standard. In, C, the following is valid: char x[10]; char *p; p = x + 9; *p++ = 'X'; p; That is, pointing one past the array is valid -- evaluating such a pointer is valid (while dereferencing it is undefined behavior). In contrast, with the file position, we cannot point one past the max representable off_t, and therefore we cannot transfer to/from the byte in the file *at* the max representable off_t. |
||||||||||||
Desired Action |
In write()/pwrite(), change "For regular files, no data transfer shall occur past the offset maximum established in the open file description associated with fildes." to "For regular files, no data transfer shall occur at or past the offset maximum established in the open file description associated with fildes." |
||||||||||||
Tags | tc1-2024 | ||||||||||||
Attached Files | |||||||||||||
|
Issue History | |||
Date Modified | Username | Field | Change |
2024-05-03 06:55 | lacos | New Issue | |
2024-05-03 06:55 | lacos | Name | => László Érsek |
2024-05-03 06:55 | lacos | Section | => pwrite, write |
2024-05-03 06:55 | lacos | Page Number | => ? |
2024-05-03 06:55 | lacos | Line Number | => ? |
2024-05-13 09:10 | geoffclare | Note Added: 0006778 | |
2024-05-19 10:20 | lacos | Note Added: 0006784 | |
2024-05-19 10:26 | lacos | Note Added: 0006785 | |
2024-05-20 08:16 | geoffclare | Note Added: 0006786 | |
2024-05-20 09:08 | lacos | Note Added: 0006787 | |
2024-05-20 16:10 | geoffclare | Interp Status | => --- |
2024-05-20 16:10 | geoffclare | Final Accepted Text | => Note: 0006786 |
2024-05-20 16:10 | geoffclare | Status | New => Resolved |
2024-05-20 16:10 | geoffclare | Resolution | Open => Accepted As Marked |
2024-05-20 16:10 | geoffclare | Tag Attached: tc1-2024 |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |