openssl/openssl
GitHub で見るPEM_read_PrivateKeyfrom() doesn't work with FILE larger than 4GiB
Open
#23,653 opened on 2024年2月21日
branch: 3.0branch: 3.1branch: 3.2branch: masterhelp wantedtriaged: bug
Repository metrics
- Stars
- (30,157 stars)
- PR merge metrics
- (30d に merged PR はありません)
説明
I have a large file with concatenated PEM private keys, when I use the PEM_read_PrivateKeyfrom() function to read them one by one, after the read pointer reaches 4GiB mark, the file is rewound to the beginning, as reported by ftell()
(the first value is the number of read private keys, the second values is position in the file):
75550000: 4100256 kiB
75560000: 4116899 kiB
75570000: 4133541 kiB
75580000: 4150184 kiB
75590000: 4166827 kiB
75600000: 4183469 kiB
75610000: 5808 kiB
75620000: 22451 kiB
75630000: 39094 kiB
75640000: 55736 kiB
75650000: 72379 kiB
75660000: 89021 kiB
75670000: 105664 kiB
75680000: 122306 kiB
75690000: 138949 kiB
75700000: 155592 kiB
this happens with a simple loop:
do {
if ((!feof(fp) &&
(pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL) == NULL))
} while (pkey);
even with #define _FILE_OFFSET_BITS 64 on a 64bit platform.
Tested with openssl-3.0.9-2.fc38.x86_64