Commit 837fddd
fix(FormData): throw exception on very large input instead of crashing
When `FormData.from()` is called with a very large ArrayBuffer (exceeding
WebKit's String::MaxLength of INT32_MAX), it would crash with an assertion
failure in WebKit's StringImpl. This fixes the issue by:
1. Adding length checks in the C++ `toString` and related functions (helpers.h)
to check against both Bun's synthetic limit and WebKit's String::MaxLength.
For UTF-8 tagged strings, we use simdutf to calculate the actual UTF-16
length only when the byte length exceeds the limit.
2. Throwing an ERR_STRING_TOO_LONG exception from createFromURLQuery when the
string is too long, instead of silently returning an empty FormData.
Changes:
- Add length checks to all UTF-8 code paths in helpers.h:
- toString(ZigString)
- toString(ZigString, StringPointer)
- toStringCopy(ZigString)
- toStringCopy(ZigString, StringPointer)
- appendToBuilder(ZigString, StringBuilder)
- Add WTF::String::MaxLength check to non-UTF-8 paths
- Throw ERR_STRING_TOO_LONG in createFromURLQuery when string is too long
- Properly propagate JSError from toJS to fromMultipartData
Now `FormData.from(new Uint32Array(913148244))` throws:
error: Cannot create a string longer than 2147483647 characters
code: "ERR_STRING_TOO_LONG"
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent ddcec61 commit 837fddd
File tree
4 files changed
+87
-12
lines changed- src
- bun.js/bindings
- test/js/web/html
4 files changed
+87
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5673 | 5673 | | |
5674 | 5674 | | |
5675 | 5675 | | |
5676 | | - | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
5677 | 5685 | | |
5678 | 5686 | | |
5679 | 5687 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
85 | 98 | | |
86 | 99 | | |
87 | | - | |
| 100 | + | |
88 | 101 | | |
89 | 102 | | |
90 | 103 | | |
| |||
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
98 | | - | |
| 111 | + | |
99 | 112 | | |
100 | 113 | | |
101 | 114 | | |
| |||
121 | 134 | | |
122 | 135 | | |
123 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
124 | 145 | | |
125 | 146 | | |
126 | 147 | | |
127 | 148 | | |
128 | | - | |
| 149 | + | |
129 | 150 | | |
130 | 151 | | |
131 | 152 | | |
| |||
141 | 162 | | |
142 | 163 | | |
143 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
144 | 173 | | |
145 | 174 | | |
146 | 175 | | |
147 | 176 | | |
148 | | - | |
| 177 | + | |
149 | 178 | | |
150 | 179 | | |
151 | 180 | | |
| |||
161 | 190 | | |
162 | 191 | | |
163 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
164 | 201 | | |
165 | 202 | | |
166 | 203 | | |
| |||
188 | 225 | | |
189 | 226 | | |
190 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
191 | 236 | | |
192 | 237 | | |
193 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
980 | 980 | | |
981 | 981 | | |
982 | 982 | | |
983 | | - | |
| 983 | + | |
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
987 | | - | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
988 | 993 | | |
989 | | - | |
| 994 | + | |
990 | 995 | | |
991 | 996 | | |
992 | 997 | | |
| |||
1041 | 1046 | | |
1042 | 1047 | | |
1043 | 1048 | | |
1044 | | - | |
| 1049 | + | |
1045 | 1050 | | |
1046 | 1051 | | |
1047 | 1052 | | |
| |||
1053 | 1058 | | |
1054 | 1059 | | |
1055 | 1060 | | |
1056 | | - | |
| 1061 | + | |
1057 | 1062 | | |
1058 | 1063 | | |
1059 | 1064 | | |
1060 | 1065 | | |
1061 | | - | |
| 1066 | + | |
1062 | 1067 | | |
1063 | 1068 | | |
1064 | 1069 | | |
| |||
1131 | 1136 | | |
1132 | 1137 | | |
1133 | 1138 | | |
1134 | | - | |
| 1139 | + | |
1135 | 1140 | | |
1136 | 1141 | | |
1137 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
280 | 297 | | |
281 | 298 | | |
282 | 299 | | |
| |||
0 commit comments