theseer / fDOMDocument

An Extension to PHP's standard DOM to add various convinience methods and exceptions by default

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insufficient error handling in save()

hschletz opened this issue · comments

DOMDocument::save() does not catch the case of running out of disk space. From the documentation:

Returns the number of bytes written or FALSE if an error occurred.

And it does just that: when it runs out of disk space, it returns the number of bytes written so far. Unless we know the expected size, this information is useless for error detection.

As fDOMDocument simply evaluates the parent's return value, it suffers from the same limitation. Instead, I pass the arguments to saveXML() and take care of the file I/O myself with thorough error handling. For reliable error handling, fDOMDocument::save() should do the same.

Test case (using vfsStream to easily simulate the disk full condition):

$root = vfsStream::setup('root');
$filename = $root->url() . '/test.xml';
$document = new fDOMDocument;
vfsStream::setQuota(1); // File is opened, written but truncated to 1 byte
$document->save($filename);

This returns 1 instead of throwing an exception.

As this project is to be Archived, I'll close this issue. Sorry for not addressing this.