Skip to content

Fix infinite recursion in FirebaseStorageError message getter #4760

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/long-forks-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'firebase': patch
'@firebase/storage': patch
---

Fix infinite recursion in FirebaseStorageError message getter
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an associated Github issue? Or an example of when the problem comes up in usage? So I can better explain to users in the release notes.

Copy link
Author

Choose a reason for hiding this comment

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

No there isn't an existing issue (beyond this PR). Basically any time the message getter is accessed you would get a Maximum call stack size exceeded Error raised.

11 changes: 5 additions & 6 deletions packages/storage/src/implementation/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ export class FirebaseStorageError extends FirebaseError {
*/
customData: { serverResponse: string | null } = { serverResponse: null };

private readonly _baseMessage: string;
/**
* @param code - A StorageErrorCode string to be prefixed with 'storage/' and
* added to the end of the message.
* @param message - Error message.
*/
constructor(code: StorageErrorCode, message: string) {
super(
prependCode(code),
`Firebase Storage: ${message} (${prependCode(code)})`
);
super(prependCode(code), '' /* unused error message */);
this._baseMessage = `Firebase Storage: ${message} (${prependCode(code)})`;
// Without this, `instanceof FirebaseStorageError`, in tests for example,
// returns false.
Object.setPrototypeOf(this, FirebaseStorageError.prototype);
Expand All @@ -54,9 +53,9 @@ export class FirebaseStorageError extends FirebaseError {
*/
get message(): string {
if (this.customData.serverResponse) {
return `${this.message}\n${this.customData.serverResponse}`;
return `${this._baseMessage}\n${this.customData.serverResponse}`;
} else {
return this.message;
return this._baseMessage;
}
}

Expand Down