-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix editor crash when shader has incorrect global array declaration #90792
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0516945
to
8a53c9f
Compare
Chaosus
reviewed
Jul 23, 2024
Chaosus
requested changes
Jul 23, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please add
else {
_set_expected_error("(");
}
after the
godot/servers/rendering/shader_language.cpp
Lines 7359 to 7402 in 4e5ed0b
if (tk.type == TK_PARENTHESIS_OPEN || curly) { // initialization | |
while (true) { | |
Node *n = _parse_and_reduce_expression(p_block, p_function_info); | |
if (!n) { | |
return ERR_PARSE_ERROR; | |
} | |
if (is_const && n->type == Node::NODE_TYPE_OPERATOR && static_cast<OperatorNode *>(n)->op == OP_CALL) { | |
_set_error(RTR("Expected a constant expression.")); | |
return ERR_PARSE_ERROR; | |
} | |
if (!_compare_datatypes(var.type, struct_name, 0, n->get_datatype(), n->get_datatype_name(), 0)) { | |
return ERR_PARSE_ERROR; | |
} | |
tk = _get_token(); | |
if (tk.type == TK_COMMA) { | |
decl.initializer.push_back(n); | |
continue; | |
} else if (!curly && tk.type == TK_PARENTHESIS_CLOSE) { | |
decl.initializer.push_back(n); | |
break; | |
} else if (curly && tk.type == TK_CURLY_BRACKET_CLOSE) { | |
decl.initializer.push_back(n); | |
break; | |
} else { | |
if (curly) { | |
_set_expected_error("}", ","); | |
} else { | |
_set_expected_error(")", ","); | |
} | |
return ERR_PARSE_ERROR; | |
} | |
} | |
if (unknown_size) { | |
decl.size = decl.initializer.size(); | |
var.array_size = decl.initializer.size(); | |
} else if (decl.initializer.size() != var.array_size) { | |
_set_error(RTR("Array size mismatch.")); | |
return ERR_PARSE_ERROR; | |
} | |
tk = _get_token(); | |
} |
(its local function case of the same problem)
8a53c9f
to
262d5c1
Compare
Chaosus
approved these changes
Jul 23, 2024
Chaosus
reviewed
Jul 23, 2024
262d5c1
to
38fad35
Compare
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trying to fix #90683
The crash happens around the change in
shader_compiler.cpp
, in that condition,cnode->array_declarations[0].initializer
has size 0 and thus usei=1
to index it will crash the editor. I leave it as a safe guard there.Note that
const bool array[1] = bool[];;
will cause the crash butconst bool array[1] = bool[];
won't (just triggerExpected a ',' or ';'
), the changes I made inshader_language.cpp
prevent this by simply don't allow a global const array to be defined without initialization, I checked the doc it didn't say whether it's legal or not, so it might not be a good idea. Feel free to correct me.