File tree Expand file tree Collapse file tree
main/php/web/session/filesystem
test/php/web/session/unittest Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ Sessions for the XP Framework ChangeLog
33
44## ?.?.? / ????-??-??
55
6+ * Fixed issue #15 : unserialize(): Extra data starting at offset [ ...]
7+ (@thekid )
8+
69## 3.2.0 / 2024-03-24
710
811* Made compatible with XP 12 - @thekid
Original file line number Diff line number Diff line change @@ -162,7 +162,12 @@ public function close() {
162162 $ modification ($ name );
163163 }
164164 $ this ->modifications = [];
165- $ this ->file ->write (serialize ($ this ->values ));
165+
166+ // Write file, ensuring to truncate any extra data
167+ $ length = $ this ->file ->write (serialize ($ this ->values ));
168+ if ($ length < $ size ) {
169+ $ this ->file ->truncate ($ length );
170+ }
166171
167172 $ this ->file ->unLock ();
168173 $ this ->file ->close ();
Original file line number Diff line number Diff line change @@ -39,4 +39,24 @@ public function session_identifiers_consist_of_32_lowercase_hex_digits() {
3939 $ id = $ sessions ->create ()->id ();
4040 Assert::matches ('/^[a-f0-9]{32}$/i ' , $ id );
4141 }
42+
43+ #[Test]
44+ public function issue_15_extra_data_during_unserialize () {
45+ $ sessions = $ this ->fixture ();
46+
47+ // Create session and register value
48+ $ a = $ sessions ->create ();
49+ $ a ->register ('name ' , 'initial ' );
50+ $ a ->close ();
51+
52+ // Overwrite initial value with a shorter one, this should truncate
53+ $ b = $ sessions ->open ($ a ->id ());
54+ $ b ->register ('name ' , 'test ' );
55+ $ b ->close ();
56+
57+ // Modify session again, should not trigger the "extra data" warning
58+ $ c = $ sessions ->open ($ a ->id ());
59+ $ c ->register ('name ' , 'irrelevant ' );
60+ $ c ->close ();
61+ }
4262}
You can’t perform that action at this time.
0 commit comments