Prevent exception on non-standard CUE sheet (#22)

* Prevent exception on non-standard CUE sheet

In case of a CUE sheet with more than about 99 tracks, this `string`
constructor [1] threw an exception, because its repetition parameter
was negative.
Fixes Exception: 'count' must be non-negative.

* Update CDImage.cs

Shortened code by use of Math.Max()

[1] 980e63d956/CUETools.CDImage/CDImage.cs (L435)
This commit is contained in:
h-h-h-h
2020-03-30 07:53:40 +02:00
committed by GitHub
parent 980e63d956
commit 5f7b450b47

View File

@@ -432,7 +432,8 @@ namespace CUETools.CDImage
for (int iTrack = 1; iTrack < AudioTracks; iTrack++)
mbSB.AppendFormat("{0:X8}", _tracks[_firstAudio + iTrack].Start - _tracks[_firstAudio].Start);
mbSB.AppendFormat("{0:X8}", _tracks[_firstAudio + (int)AudioTracks - 1].End + 1 - _tracks[_firstAudio].Start);
mbSB.Append(new string('0', (100 - (int)AudioTracks) * 8));
// Use Math.Max() to avoid negative count number in case of non-standard CUE sheet with more than 99 tracks.
mbSB.Append(new string('0', Math.Max(0, (100 - (int)AudioTracks) * 8)));
byte[] hashBytes = (new SHA1CryptoServiceProvider()).ComputeHash(Encoding.ASCII.GetBytes(mbSB.ToString()));
return Convert.ToBase64String(hashBytes).Replace('+', '.').Replace('/', '_').Replace('=', '-');
}