Index: /trunk/src/VBox/Storage/VMDK.cpp
===================================================================
--- /trunk/src/VBox/Storage/VMDK.cpp	(revision 61851)
+++ /trunk/src/VBox/Storage/VMDK.cpp	(revision 61852)
@@ -3079,7 +3079,17 @@
         /* HACK: extend the descriptor if it is unusually small and it fits in
          * the unused space after the image header. Allows opening VMDK files
-         * with extremely small descriptor in read/write mode. */
-        if (    !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
-            &&  pExtent->cDescriptorSectors < 3
+         * with extremely small descriptor in read/write mode.
+         *
+         * The previous version introduced a possible regression for VMDK stream
+         * optimized images from VMware which tend to have only a single sector sized
+         * descriptor. Increasing the descriptor size resulted in adding the various uuid
+         * entries required to make it work with VBox but for stream optimized images
+         * the updated binary header wasn't written to the disk creating a mismatch
+         * between advertised and real descriptor size.
+         *
+         * The descriptor size will be increased even if opened readonly now if there
+         * enough room but the new value will not be written back to the image.
+         */
+        if (    pExtent->cDescriptorSectors < 3
             &&  (int64_t)pExtent->uSectorGD - pExtent->uDescriptorSector >= 4
             &&  (!pExtent->uSectorRGD || (int64_t)pExtent->uSectorRGD - pExtent->uDescriptorSector >= 4))
@@ -3088,18 +3098,21 @@
 
             pExtent->cDescriptorSectors = 4;
-            /*
-             * Update the on disk number now to make sure we don't introduce inconsistencies
-             * in case of stream optimized images from VMware where the descriptor is just
-             * one sector big (the binary header is not written to disk for complete
-             * stream optimized images in vmdkFlushImage()).
-             */
-            uint64_t u64DescSizeNew = RT_H2LE_U64(pExtent->cDescriptorSectors);
-            rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pFile->pStorage, RT_OFFSETOF(SparseExtentHeader, descriptorSize),
-                                        &u64DescSizeNew, sizeof(u64DescSizeNew));
-            if (RT_FAILURE(rc))
+            if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
             {
-                LogFlowFunc(("Increasing the descriptor size failed with %Rrc\n", rc));
-                /* Restore the old size and carry on. */
-                pExtent->cDescriptorSectors = cDescriptorSectorsOld;
+                /*
+                 * Update the on disk number now to make sure we don't introduce inconsistencies
+                 * in case of stream optimized images from VMware where the descriptor is just
+                 * one sector big (the binary header is not written to disk for complete
+                 * stream optimized images in vmdkFlushImage()).
+                 */
+                uint64_t u64DescSizeNew = RT_H2LE_U64(pExtent->cDescriptorSectors);
+                rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pFile->pStorage, RT_OFFSETOF(SparseExtentHeader, descriptorSize),
+                                            &u64DescSizeNew, sizeof(u64DescSizeNew));
+                if (RT_FAILURE(rc))
+                {
+                    LogFlowFunc(("Increasing the descriptor size failed with %Rrc\n", rc));
+                    /* Restore the old size and carry on. */
+                    pExtent->cDescriptorSectors = cDescriptorSectorsOld;
+                }
             }
         }
