claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
56 stars 17 forks source link

Some file contains negative time and then causes Exception #77

Open 270676504 opened 6 months ago

270676504 commented 6 months ago

The Exception is:"The added or subtracted value results in an un-representable DateTime. Arg_ParamName_Name" Simply adding try-catch can fix this problem. public NSDate(ReadOnlySpan bytes) { try { Date = EPOCH.AddSeconds(BinaryPropertyListParser.ParseDouble(bytes)); } catch (Exception) { Date = EPOCH; } }

270676504 commented 6 months ago
  public NSDate(ReadOnlySpan<byte> bytes)
  {
      //dates are 8 byte big-endian double, seconds since the epoch
      try
      {
          Date = EPOCH.AddSeconds(BinaryPropertyListParser.ParseDouble(bytes));

      }
      catch
      {
          Date = EPOCH;
      }
  }