diff --git a/AppleWin/docs/History.txt b/AppleWin/docs/History.txt index e7bac1df..ce735d7b 100644 --- a/AppleWin/docs/History.txt +++ b/AppleWin/docs/History.txt @@ -12,6 +12,14 @@ https://developer.berlios.de/feature/?func=addfeature&group_id=6117 Tom Charlesworth tomch at users.berlios.de + +Latest: +------- + +Fixes: +. [ Bug #19154 ] ProDOS Order 2IMG crashing + + 1.23.2 - 14 Sep 2013 -------------------- Changes: diff --git a/AppleWin/source/DiskImageHelper.cpp b/AppleWin/source/DiskImageHelper.cpp index 90c4885e..ff53ab1a 100644 --- a/AppleWin/source/DiskImageHelper.cpp +++ b/AppleWin/source/DiskImageHelper.cpp @@ -596,7 +596,7 @@ public: { if ((*(LPWORD)(pImage+(loop << 9)+0x100) != ((loop == 5) ? 0 : 6-loop)) || (*(LPWORD)(pImage+(loop << 9)+0x102) != ((loop == 2) ? 0 : 8-loop))) - bMismatch = 1; + bMismatch = true; } if (!bMismatch) return eMatch; @@ -647,8 +647,10 @@ public: int loop = 4; bool bMismatch = false; while ((loop++ < 13) && !bMismatch) + { if (*(pImage+0x11002+(loop << 8)) != 14-loop) bMismatch = true; + } if (!bMismatch) return eMatch; } @@ -1473,16 +1475,34 @@ CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* p eImageType ImageType = eImageUNKNOWN; eImageType PossibleType = eImageUNKNOWN; - for (UINT uLoop=0; uLoop < GetNumImages() && ImageType == eImageUNKNOWN; uLoop++) + if (m_Result2IMG == eMatch) { - if (*pszExt && _tcsstr(GetImage(uLoop)->GetRejectExtensions(), pszExt)) - continue; + if (m_2IMGHelper.IsImageFormatDOS33()) + ImageType = eImageDO; + else if (m_2IMGHelper.IsImageFormatProDOS()) + ImageType = eImagePO; - eDetectResult Result = GetImage(uLoop)->Detect(pImage, dwSize, pszExt); - if (Result == eMatch) - ImageType = GetImage(uLoop)->GetType(); - else if ((Result == ePossibleMatch) && (PossibleType == eImageUNKNOWN)) - PossibleType = GetImage(uLoop)->GetType(); + if (ImageType != eImageUNKNOWN) + { + CImageBase* pImageType = GetImage(ImageType); + if (!pImageType || !pImageType->IsValidImageSize(dwSize)) + ImageType = eImageUNKNOWN; + } + } + + if (ImageType == eImageUNKNOWN) + { + for (UINT uLoop=0; uLoop < GetNumImages() && ImageType == eImageUNKNOWN; uLoop++) + { + if (*pszExt && _tcsstr(GetImage(uLoop)->GetRejectExtensions(), pszExt)) + continue; + + eDetectResult Result = GetImage(uLoop)->Detect(pImage, dwSize, pszExt); + if (Result == eMatch) + ImageType = GetImage(uLoop)->GetType(); + else if ((Result == ePossibleMatch) && (PossibleType == eImageUNKNOWN)) + PossibleType = GetImage(uLoop)->GetType(); + } } if (ImageType == eImageUNKNOWN) diff --git a/AppleWin/source/DiskImageHelper.h b/AppleWin/source/DiskImageHelper.h index 575a088b..711d83d6 100644 --- a/AppleWin/source/DiskImageHelper.h +++ b/AppleWin/source/DiskImageHelper.h @@ -63,6 +63,7 @@ public: virtual char* GetRejectExtensions(void) = 0; void SetVolumeNumber(const BYTE uVolumeNumber) { m_uVolumeNumber = uVolumeNumber; } + bool IsValidImageSize(const DWORD uImageSize); enum SectorOrder_e {eProDOSOrder, eDOSOrder, eSIMSYSTEMOrder, NUM_SECTOR_ORDERS}; @@ -77,7 +78,6 @@ protected: void DenibblizeTrack (LPBYTE trackimage, SectorOrder_e SectorOrder, int nibbles); DWORD NibblizeTrack (LPBYTE trackimagebuffer, SectorOrder_e SectorOrder, int track); void SkewTrack (const int nTrack, const int nNumNibbles, const LPBYTE pTrackImageBuffer); - bool IsValidImageSize(const DWORD uImageSize); public: static LPBYTE ms_pWorkBuffer; @@ -127,6 +127,8 @@ public: virtual UINT GetMaxHdrSize(void) { return sizeof(Header2IMG); } BYTE GetVolumeNumber(void); bool IsLocked(void); + bool IsImageFormatDOS33(void) { return m_Hdr.ImageFormat == e2IMGFormatDOS33; } + bool IsImageFormatProDOS(void) { return m_Hdr.ImageFormat == e2IMGFormatProDOS; } private: static const UINT32 FormatID_2IMG = 'GMI2'; // '2IMG'