Make WordPress Core

Opened 4 years ago

Last modified 12 months ago

#57741 new defect (bug)

Core throwing 'Attempt to read property "post_type" on null'

Reported by: haykuro Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version:
Severity: normal Keywords: reporter-feedback
Cc: Focuses:

Description

A calls B. B calls C.

C is calling get_post() passing in args from B.

C then proceeds to immediately use the results of get_post() ($post->post_type) without checking the response, resulting in an edge condition where a warning is thrown: Attempt to read property "post_type" on null

A: https://github.com/WordPress/WordPress/blob/f0789b64238a97adc3ce0c9b8cdf33c1753f550c/wp-admin/post.php#L186-L189

B: https://github.com/WordPress/WordPress/blob/f0789b64238a97adc3ce0c9b8cdf33c1753f550c/wp-admin/edit-form-blocks.php#L249-L253

C: https://github.com/WordPress/WordPress/blob/f0789b64238a97adc3ce0c9b8cdf33c1753f550c/wp-includes/media.php#L4552-L4558

Change History (2)

#1 @SergeyBiryukov
4 years ago

  • Component GeneralPosts, Post Types

#2 @SirLouen
12 months ago

  • Component Posts, Post TypesMedia
  • Keywords reporter-feedback added
  • Version 6.1.1

@haykuro yes, looking at the logic, this can definitely happen.
I have not dug too much into possibilities because I'm currently triaging tickets, but I wonder if this can be happening on a healthy WP or if this is caused by a faulty code brought by a plugin or something like that.
But can you explain the exact conditions for this to happen, ideally step by step
If you can reproduce this in WordPress Playground it would be better.

Note: See TracTickets for help on using tickets.