Hi
add_string_to_pool for check write correct file rests on strlen function, but strlen calculate size of string before read \0 symbol. In this case length of strlen and length of file_put_contents may be differs with actual length write by file_put_contents.
In my case: I can't import questions with images, because moodle crash when tries create image.
Call stack: line 2080 of /lib/filestorage/file_storage.php: file_exception thrown
line 1587 of /lib/filestorage/file_storage.php: call to file_storage->add_string_to_pool()
line 239 of /question/format/xml/format.php: call to file_storage->create_file_from_string()
line 597 of /question/format/xml/format.php: call to qformat_xml->import_headers()
line 973 of /question/format/xml/format.php: call to qformat_xml->import_shortanswer()
line 951 of /question/format/xml/format.php: call to qformat_xml->import_question()
line 939 of /question/format/xml/format.php: call to qformat_xml->import_questions()
line 304 of /question/format.php: call to qformat_xml->readquestions()
line 123 of /question/import.php: call to qformat_default->importprocess()
Some lines can have offset, because I add debug print messages.
Additional info:
Some variables:
$filerecord: Array ( [contextid] => 1866 [component] => user [filearea] => draft [itemid] => 77325933 [filepath] => / [filename] => Images_forQuizQuestions_STP_ОсновыCSharpNET1.png )
$hashfile: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
$hashfile333: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
$hashfile333b: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
$newsize: 8790
$filesize: 6787
strlen($content): 6787
$hashfile555: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
In this print variables you can see different sizes in $newsize from file_put_contents have more value than $filesize and strlen($content). For check that of length is correct, I extract base64 conent from XML and place this in one line on new file. Text editor show me 11720 symbols from begin. Than I calculate to standard byte: (11720*6)/8=8790. It's equal with length factual wrote by file_put_contents function.
My version moodle is 3.1.1+ 20160908b
I attach file with questions.
Thanks,
Artem Matveev
- will be (partly) resolved by
-
MDL-53723 Normalize how we count bytes in a variable
-
- Open
-