Index: trunk/src/VBox/Main/include/ovfreader.h
===================================================================
--- trunk/src/VBox/Main/include/ovfreader.h	(revision 99466)
+++ trunk/src/VBox/Main/include/ovfreader.h	(revision 99523)
@@ -635,5 +635,5 @@
     HardwareItemVector  vecHardwareItems;       //< vector containing all virtual hardware items in parsing order.
 
-    uint64_t            ullMemorySize;          // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
+    uint64_t            ullMemorySize;          // always in Megabytes, copied from llHardwareItems; default = 0 (unspecified)
     uint16_t            cCPUs;                  // no. of CPUs, copied from llHardwareItems; default = 1
 
Index: trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 99466)
+++ trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp	(revision 99523)
@@ -188,5 +188,5 @@
 
         /* Memory */
-        Utf8Str strMemory = Utf8StrFmt("%RI64", (uint64_t)ulMemSizeMB * _1M);
+        Utf8Str strMemory = Utf8StrFmt("%RI64", (uint64_t)ulMemSizeMB);
         pNewDesc->i_addEntry(VirtualSystemDescriptionType_Memory,
                              "",
@@ -1617,5 +1617,5 @@
                         type = ovf::ResourceType_Memory; // 4
                         desc.strVBoxCurrent.toInt(uTemp);
-                        lVirtualQuantity = (int32_t)(uTemp / _1M);
+                        lVirtualQuantity = (int32_t)(uTemp);
                         strAllocationUnits = "MegaBytes";
                         strCaption = Utf8StrFmt("%d MB of memory", lVirtualQuantity);     // without this ovftool
@@ -1815,5 +1815,4 @@
                                            tr("Missing or bad extra config string in hard disk image: \"%s\""),
                                            desc.strExtraConfigCurrent.c_str());
-
                         stack.mapDisks[strDiskID] = &desc;
 
Index: trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 99466)
+++ trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 99523)
@@ -342,11 +342,11 @@
             if (   vsysThis.pelmVBoxMachine
                 && pNewDesc->m->pConfig->hardwareMachine.ulMemorySizeMB)
-                ullMemSizeVBox = (uint64_t)pNewDesc->m->pConfig->hardwareMachine.ulMemorySizeMB * _1M;
+                ullMemSizeVBox = (uint64_t)pNewDesc->m->pConfig->hardwareMachine.ulMemorySizeMB;
             else
-                ullMemSizeVBox = vsysThis.ullMemorySize;  /* already in bytes via OVFReader::HandleVirtualSystemContent() */
+                ullMemSizeVBox = vsysThis.ullMemorySize;  /* already in Megabytes via OVFReader::HandleVirtualSystemContent() */
             /* Check for the constraints */
             if (    ullMemSizeVBox != 0
-                 && (    ullMemSizeVBox < MM_RAM_MIN
-                      || ullMemSizeVBox > MM_RAM_MAX
+                 && (    ullMemSizeVBox < MM_RAM_MIN_IN_MB
+                      || ullMemSizeVBox > MM_RAM_MAX_IN_MB
                     )
                )
@@ -355,6 +355,6 @@
                                 "however VirtualBox supports a minimum of %u MB and a maximum of %u MB "
                                 "of memory."),
-                                vsysThis.strName.c_str(), ullMemSizeVBox / _1M, MM_RAM_MIN_IN_MB, MM_RAM_MAX_IN_MB);
-                ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, MM_RAM_MIN), MM_RAM_MAX);
+                                vsysThis.strName.c_str(), ullMemSizeVBox, MM_RAM_MIN_IN_MB, MM_RAM_MAX_IN_MB);
+                ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, MM_RAM_MIN_IN_MB), MM_RAM_MAX_IN_MB);
             }
             if (vsysThis.ullMemorySize == 0)
@@ -369,6 +369,6 @@
                 else
                     memSizeVBox2 = 1024;
-                /* IGuestOSType::recommendedRAM() returns the size in MB so convert to bytes */
-                ullMemSizeVBox = (uint64_t)memSizeVBox2 * _1M;
+                /* IGuestOSType::recommendedRAM() returns the size in MB */
+                ullMemSizeVBox = (uint64_t)memSizeVBox2;
             }
             pNewDesc->i_addEntry(VirtualSystemDescriptionType_Memory,
@@ -1533,7 +1533,7 @@
                 // RAM
                 GET_VSD_DESCRIPTION_BY_TYPE(VirtualSystemDescriptionType_Memory);
-                if (aVBoxValues.size() == 0)//1000MB by default
+                if (aVBoxValues.size() == 0)//1024MB by default, 1,073,741,824 in bytes
                     vsd->AddDescription(VirtualSystemDescriptionType_Memory,
-                                        Bstr("1000").raw(),
+                                        Bstr("1024").raw(),
                                         NULL);
 
@@ -1797,14 +1797,16 @@
                 }
 
-                ULONG memory;//Mb
+                ULONG memory = 1024;//1024MB by default, 1,073,741,824 in bytes
                 pGuestOSType->COMGETTER(RecommendedRAM)(&memory);
                 {
+                    //note! Memory must be stored in Megabytes on the earlier stages for the correct comparison here
                     GET_VSD_DESCRIPTION_BY_TYPE(VirtualSystemDescriptionType_Memory); //aVBoxValues is set in this #define
                     if (aVBoxValues.size() != 0)
                     {
                         vsdData = aVBoxValues[0];
-                        if (memory > vsdData.toUInt32())
-                            memory = vsdData.toUInt32();
+                        memory = RT_MIN(RT_MAX(vsdData.toUInt32(), MM_RAM_MIN_IN_MB), MM_RAM_MAX_IN_MB);
+
                     }
+                    //and set in ovf::VirtualSystem in Megabytes
                     vsys.ullMemorySize = memory;
                     LogRel(("%s: Size of RAM is %d MB\n", __FUNCTION__, vsys.ullMemorySize));
@@ -6114,5 +6116,6 @@
         if (vsdeRAM.size() != 1)
             throw setError(VBOX_E_FILE_ERROR, tr("RAM size missing"));
-        uint64_t ullMemorySizeMB = vsdeRAM.front()->strVBoxCurrent.toUInt64() / _1M;
+        //Returned value must be in MB
+        uint64_t ullMemorySizeMB = vsdeRAM.front()->strVBoxCurrent.toUInt64();
         stack.ulMemorySizeMB = (uint32_t)ullMemorySizeMB;
 
Index: trunk/src/VBox/Main/xml/ovfreader.cpp
===================================================================
--- trunk/src/VBox/Main/xml/ovfreader.cpp	(revision 99466)
+++ trunk/src/VBox/Main/xml/ovfreader.cpp	(revision 99523)
@@ -525,5 +525,10 @@
                              || i.strAllocationUnits == "byte * 2^20"         // suggested by OVF spec DSP0243 page 21
                            )
-                            vsys.ullMemorySize = i.ullVirtualQuantity * _1M;
+                            vsys.ullMemorySize = i.ullVirtualQuantity;
+                        else if ( i.strAllocationUnits == "GigaBytes"
+                                  || i.strAllocationUnits == "GB"
+                                  || i.strAllocationUnits == "byte * 2^30"
+                           )
+                            vsys.ullMemorySize = i.ullVirtualQuantity/_1K;//back to MB
                         else
                             throw OVFLogicError(N_("Error reading \"%s\": Invalid allocation unit \"%s\" specified with memory size item, line %d"),
