@@ -143,7 +143,12 @@ protected override void WriteSingleItem(
143
143
}
144
144
}
145
145
146
- WriteMethodBodies ( item . Methods , item . Interfaces , writer ) ;
146
+ WriteMethodBodies (
147
+ item . FullName ,
148
+ item . Methods ,
149
+ item . Interfaces ,
150
+ writer
151
+ ) ;
147
152
148
153
_context . SignaturesTable . WriteDataType ( item , writer , false , true , true ) ;
149
154
@@ -227,6 +232,7 @@ private void WriteClassFields(
227
232
}
228
233
229
234
private void WriteMethodBodies (
235
+ string typeName ,
230
236
Collection < MethodDefinition > methods ,
231
237
Collection < InterfaceImplementation > iInterfaces ,
232
238
nanoBinaryWriter writer )
@@ -265,6 +271,22 @@ private void WriteMethodBodies(
265
271
266
272
writer . WriteUInt16 ( firstMethodId ) ;
267
273
274
+ // sanity checks
275
+ if ( virtualMethodsCount > byte . MaxValue )
276
+ {
277
+ throw new InvalidOperationException ( $ "Fatal error processing '{ typeName } ', virtual methods count ({ virtualMethodsCount } ) exceeds maximum supported (255).") ;
278
+ }
279
+
280
+ if ( instanceMethodsCount > byte . MaxValue )
281
+ {
282
+ throw new InvalidOperationException ( $ "Fatal error processing '{ typeName } ', instance methods count ({ instanceMethodsCount } ) exceeds maximum supported (255).") ;
283
+ }
284
+
285
+ if ( staticMethodsCount > byte . MaxValue )
286
+ {
287
+ throw new InvalidOperationException ( $ "Fatal error processing '{ typeName } ', static methods count ({ staticMethodsCount } ) exceeds maximum supported (255).") ;
288
+ }
289
+
268
290
writer . WriteByte ( ( byte ) virtualMethodsCount ) ;
269
291
writer . WriteByte ( ( byte ) instanceMethodsCount ) ;
270
292
writer . WriteByte ( ( byte ) staticMethodsCount ) ;
0 commit comments