Repository: electron/electron (language: cpp)

Issue:
[Bug]: Window maxWidth and maxHeight is ignore if one of them set to 0
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

17.4.1

### What operating system are you using?

Windows

### Operating System Version

Windows 10

### What arch are you using?

x64

### Last Known Working Electron version

_No response_

### Expected Behavior

If one of BrowserWindow settings maxWidth or maxHeight is set to 0 and another one set to any positive value more than 0 the window will resize with limit by width or height if it set to positive value and with no limit by another one.
```javascript
new BrowserWindow({
    x: 1000,
    y: 800,
    maxWidth: 0,
    maxHeight: 500,
})
```

### Actual Behavior

If I set one of maxWidth or maxHeight for BrowserWindow to 0 and another one to any positive value more than 0 the window ignore this non zero value and can resize with no limit by width and height.

### Testcase Gist URL

_No response_

### Additional Information

_No response_


Discussion / hints:
Also if I try to set maximum window size to [0, 0], the new size is not accepted and stays the same.
If current max size is [1000, 1000]:
```js
window.setMaximumSize(0, 0);

console.log(window.getMaximumSize()) //output [1000, 1000]
```
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!
Hah, setting maxWidth to 0 seems to cause some quite odd behavior just by itself, at least on macOS: https://gist.github.com/6e554554bd6cc9498359f2333ca3ae30

1. Run the above fiddle
2. Try to resize the window

I get a beachball and then the window disappears after a few seconds. But no crash? Very strange.

Fix patch:
diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc
index fd1be39c6c5f1..47429f086428b 100644
--- a/shell/browser/native_window.cc
+++ b/shell/browser/native_window.cc
@@ -175,7 +175,11 @@ void NativeWindow::InitFromOptions(const gin_helper::Dictionary& options) {
   int max_width = max_size.width() > 0 ? max_size.width() : INT_MAX;
   int max_height = max_size.height() > 0 ? max_size.height() : INT_MAX;
   bool have_max_width = options.Get(options::kMaxWidth, &max_width);
+  if (have_max_width && max_width <= 0)
+    max_width = INT_MAX;
   bool have_max_height = options.Get(options::kMaxHeight, &max_height);
+  if (have_max_height && max_height <= 0)
+    max_height = INT_MAX;
 
   // By default the window has a default maximum size that prevents it
   // from being resized larger than the screen, so we should only set this


Test patch: