Skip to content

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Feb 9, 2026

This also fixes bug 71162.

I'm targeting master with this change as it is long-standing behaviour, but I don't really understand why an "empty session" would fail to encode. Similarly, with a "partial" encoding of it when discarding numeric keys.

The biggest impact is that session_encode() now only returns false in very limited cases and for empty sessions returns an empty string, which is how it was encoded anyway when actually performing session writes.

// TODO warn that ID cannot be verified? else { }
}
/* Read is required to make new session data at this point. */
zend_string *data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be initialised to NULL wdyt ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it wasn't previously though, so is that a bug then do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure all callbacks guarantee initialisation, this is all I m saying but I do not session that well :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was always initialized prior to the rename because it would either be NULL or hold a dangling pointer. So not sure there is a bug, but I'll initialize it to NULL just because it's the most sensible.

smart_str_appendc(&buf, PS_DELIMITER);
php_var_serialize(&buf, struc, &var_hash);
);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a bug: now var_hash is destroyed twice because it is already destroyed at line 1039 too. I think you may drop line 1039.

// TODO warn that ID cannot be verified? else { }
}
/* Read is required to make new session data at this point. */
zend_string *data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it wasn't previously though, so is that a bug then do you think?

@Girgias Girgias force-pushed the 2026-02-session-if-encode-null-then-failure branch from 51cc14b to 37698f3 Compare February 10, 2026 12:52
@Girgias Girgias marked this pull request as ready for review February 10, 2026 14:00
Copy link
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks logical, not sure how big the BC impact is, I'll leave that assessment to you. Although I presume that the edge case where this happens doesn't occur much in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants