{"record":{"id":"6ff67352b6a6d6f9","repo":"hashicorp/nomad","slug":"qemu-memory-assignment-out-of-bounds","errorCode":null,"errorMessage":"QEMU memory assignment out of bounds","messagePattern":"QEMU memory assignment out of bounds","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/qemu/driver.go","lineNumber":512,"sourceCode":"\temulator := \"x86_64\"\n\tif driverConfig.Emulator != \"\" {\n\t\t// COMPAT: TrimPrefix to support full emulator name\n\t\t// which was required in 1.11.1.\n\t\temulator = strings.TrimPrefix(driverConfig.Emulator, \"qemu-system-\")\n\n\t}\n\taccelerator := \"tcg\"\n\tif driverConfig.Accelerator != \"\" {\n\t\taccelerator = driverConfig.Accelerator\n\t}\n\tmachineType := \"pc\"\n\tif driverConfig.MachineType != \"\" {\n\t\tmachineType = driverConfig.MachineType\n\t}\n\n\tmb := cfg.Resources.NomadResources.Memory.MemoryMB\n\tif mb < 128 || mb > 4000000 {\n\t\treturn nil, nil, fmt.Errorf(\"QEMU memory assignment out of bounds\")\n\t}\n\tmem := fmt.Sprintf(\"%dM\", mb)\n\n\tabsPath, err := GetAbsolutePath(fmt.Sprintf(\"qemu-system-%s\", emulator))\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tdriveInterface := \"ide\"\n\tif driverConfig.DriveInterface != \"\" {\n\t\tdriveInterface = driverConfig.DriveInterface\n\t}\n\tif !isAllowedDriveInterface(driveInterface) {\n\t\treturn nil, nil, fmt.Errorf(\"Unsupported drive_interface\")\n\t}\n\n\targs := []string{\n\t\tabsPath,","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/qemu/driver.go#L494-L530","documentation":"Before building QEMU's -m memory argument, StartTask bounds-checks the task's Memory.MemoryMB from the resources block: it must be between 128 MB and 4,000,000 MB. Values outside that range make StartTask fail. This catches invalid resource declarations (including missing/zero memory, which lands below the 128 MB floor) before spawning the VM.","triggerScenarios":"Starting a QEMU task whose resources.memory = 0 or missing (below 128); resources.memory > 4000000 MB (over 4 TB); a misconfigured template or variable interpolation yielding a huge or zero MemoryMB.","commonSituations":"Task author forgets the memory stanza entirely (defaults to 0); copy-paste of a docker task config with tiny/absent memory; accidentally specifying memory in KB or bytes; deliberate test of an extreme value above 4,000,000.","solutions":["Set resources.memory to a value between 128 and 4000000 MB in the task's resources block.","If the VM needs more than ~4 TB, split workloads or use a different driver/host configuration, since the driver hard-caps at 4000000 MB.","Check interpolated values (variables/templating) that produce 0 or an absurdly large number."],"exampleFix":"// before\nresources {\n  cpu    = 500\n}\n// after\nresources {\n  cpu    = 500\n  memory = 512\n}","handlingStrategy":"validation","validationCode":"function validateQemuMemory(resources) {\n  const mb = resources?.NomadResources?.Memory?.MemoryMB ?? resources?.memory ?? 0;\n  if (mb < 128 || mb > 4000000) {\n    throw new Error(`QEMU memory assignment out of bounds: got ${mb} MB, need 128..4000000`);\n  }\n}\nvalidateQemuMemory(taskJson.resources);","typeGuard":"function hasValidMemoryMB(res) {\n  const mb = res?.NomadResources?.Memory?.MemoryMB;\n  return typeof mb === \"number\" && Number.isFinite(mb) && mb >= 128 && mb <= 4000000;\n}","tryCatchPattern":"try {\n  await nomad.jobs.register(job);\n} catch (e) {\n  if (String(e.message).includes(\"QEMU memory assignment out of bounds\")) {\n    console.error(\"Set resources.memory to 128..4000000 MB\");\n  }\n  throw e;\n}","preventionTips":["Always declare an explicit memory value in the resources block for QEMU tasks.","Lint job specs: assert MemoryMB within [128, 4000000] in CI.","Remember units are MB; convert GB with *1024 before templating.","Watch for template interpolation returning empty string (yields 0)."],"tags":["qemu","resources","validation","memory"],"backgroundTag":"resource-limit-exceeded","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}