Bladeren bron

More type encoding parser tests + bug fixes

Tanner Bennett 6 jaren geleden
bovenliggende
commit
06655dde6a
2 gewijzigde bestanden met toevoegingen van 32 en 5 verwijderingen
  1. 12 5
      Classes/Utility/Runtime/Objc/FLEXTypeEncodingParser.m
  2. 20 0
      FLEXTests/FLEXTypeEncodingParserTests.m

+ 12 - 5
Classes/Utility/Runtime/Objc/FLEXTypeEncodingParser.m

@@ -119,7 +119,7 @@ BOOL FLEXGetSizeAndAlignment(const char *type, NSUInteger *sizep, NSUInteger *al
     while (!parser.scan.isAtEnd) {
         FLEXTypeInfo info = [parser parseNextType];
         
-        if (!info.supported || info.containsUnion) {
+        if (!info.supported || info.containsUnion || info.size == 0) {
             return NO;
         }
     }
@@ -301,15 +301,17 @@ BOOL FLEXGetSizeAndAlignment(const char *type, NSUInteger *sizep, NSUInteger *al
             // (Unions are supported by NSGetSizeAndAlignment but not
             // supported by NSMethodSignature for some reason)
             if (needsCleaning) {
-                // if unsupported, no cleaning occurred in parseType:cleaned: above.
+                // If unsupported, no cleaning occurred in parseType:cleaned: above.
                 // Otherwise, the type is partially supported and we did clean it,
                 // and we will replace this type with the cleaned type from above.
                 if (!info.supported || info.containsUnion) {
                     cleaned = [self cleanPointeeTypeAtLocation:pointerTypeStart];
                 }
                 
+                NSInteger offset = self.cleanedReplacingOffset;
+                NSInteger location = pointerTypeStart - offset;
                 [self.cleaned replaceCharactersInRange:NSMakeRange(
-                    pointerTypeStart - self.cleanedReplacingOffset, pointerTypeLength
+                    location, pointerTypeLength
                 ) withString:cleaned];
             }
             
@@ -380,7 +382,11 @@ BOOL FLEXGetSizeAndAlignment(const char *type, NSUInteger *sizep, NSUInteger *al
             // If we encounter the ?= portion of something like {?=b8b4b1b1b18[8S]}
             // then we skip over it, since it means nothing to us in this context.
             // It is completely optional, and if it fails, we go right back where we were.
-            [self scanTypeName];
+            if (![self scanTypeName] && self.nextChar == FLEXTypeEncodingUnknown) {
+                // Exception: we are trying to parse {?} which is invalid
+                self.scan.scanLocation = start;
+                return FLEXTypeInfoUnsupported;
+            }
         }
 
         // Sum sizes of members together:
@@ -832,8 +838,9 @@ BOOL FLEXGetSizeAndAlignment(const char *type, NSUInteger *sizep, NSUInteger *al
             return @"?";
             
         case FLEXTypeEncodingStructBegin: {
-            FLEXTypeInfo info = [self parseNextType];
+            FLEXTypeInfo info = [self.class parseType:self.unscanned];
             if (info.supported && !info.fixesApplied) {
+                [self scanPastArg];
                 return typeIsClean();
             }
             

+ 20 - 0
FLEXTests/FLEXTypeEncodingParserTests.m

@@ -197,6 +197,7 @@ typedef struct HasUnion {
 
 - (void)testUnsupportedMethodSignatures {
     NSArray<NSString *> *unsupported = @[
+        @"v40@0:8{?=}16d32",
         @"{?=[4]}16@0:8}",
         @"i48@0:8^{__CVBuffer=}16I24(pj_timestamp={?=II}Q)28i36B40B44",
     ];
@@ -208,6 +209,25 @@ typedef struct HasUnion {
 
 - (void)testMethodSignatureCleaning {
     NSDictionary<NSString *, NSString *> *uncleanToClean = @{
+        @"^{Layer=^^?{Atomic={?=i}}{Data={Vec4<float>=ffff}b1{Vec2<double>=dd}{Rect=dddd}}"
+        "{Ref<CA::Render::Object>=^{Object}}{Ref<CA::Render::TypedArray<CA::Render::Layer> >="
+        "^{TypedArray<CA::Render::Layer>}}^{Layer}{Ref<CA::Render::Layer::Ext>=^{Ext}}"
+        "{Ref<CA::Render::TypedArray<CA::Render::Animation> >="
+        "^{TypedArray<CA::Render::Animation>}}{Ref<CA::Render::Handle>=^{Handle}}}36@0:"
+        "8^{Transaction=^{Shared}i^{HashTable<CA::Layer *, unsigned int *>}^{SpinLock}I"
+        "^{Level}^{List<void (^)()>}^{Command}^{Deleted}^{List<const void *>}^{Context}"
+        "^{HashTable<CA::Layer *, CA::Layer *>}^{__CFRunLoop}^{__CFRunLoopObserver}"
+        "^{LayoutList}^{List<CA::Layer *>}{Atomic={?=i}}b1b1b1b1b1}16I24^I28":
+            @"^{Layer=}36@0:8^{Transaction=}16I24^I28",
+        
+        @"{LSBinding=I^{LSBundleData=}I^{?}@@}16@0:8":
+            @"{LSBinding=I^{LSBundleData=}I^{?=}@@}16@0:8",
+        
+        @"@40@0:8@16r^{?=BQ^{?}}24^@32": @"@40@0:8@16r^{?=BQ^{?=}}24^@32",
+        
+        @"@36@0:8@16^{mig_subsystem=^?iiIQ[1{routine_descriptor=^?^?II^{?}I}]}24B32":
+            @"@36@0:8@16^{mig_subsystem=^?iiIQ[1{routine_descriptor=^?^?II^{?=}I}]}24B32",
+        
         @"@28@0:8r^{basic_string<char, std::__1::char_traits<char>, "
         "std::__1::allocator<char> >={__compressed_pair<std::__1::"
         "basic_string<char, std::__1::char_traits<char>, "