{"record":{"id":"cac4c47e3ed34b54","repo":"mudler/LocalAI","slug":"audio-too-large-for-32-bit-wav-priu64-bytes-n","errorCode":null,"errorMessage":"audio too large for 32-bit WAV (%PRIu64 bytes)\\n","messagePattern":"audio too large for 32-bit WAV \\(%PRIu64 bytes\\)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":1165,"sourceCode":"// Returns 0 on success and fills wav_path (must be at least 64 bytes).\nstatic int write_planar_float_wav(const sd_audio_t* a, char* wav_path, size_t wav_path_sz) {\n    if (!a || !a->data || a->sample_count == 0 || a->channels == 0 || a->sample_rate == 0) {\n        return -1;\n    }\n\n    snprintf(wav_path, wav_path_sz, \"/tmp/gosd-audio-XXXXXX.wav\");\n    int fd = mkstemps(wav_path, 4);\n    if (fd < 0) { perror(\"mkstemps wav\"); return -1; }\n    FILE* f = fdopen(fd, \"wb\");\n    if (!f) { perror(\"fdopen wav\"); close(fd); return -1; }\n\n    uint64_t frames = a->sample_count;\n    uint32_t channels = a->channels;\n    uint32_t sample_rate = a->sample_rate;\n    uint64_t total_samples64 = frames * (uint64_t)channels;\n    uint64_t data_bytes64 = total_samples64 * sizeof(float);\n    if (data_bytes64 > 0xFFFFFFFFull - 44) {\n        fprintf(stderr, \"audio too large for 32-bit WAV (%\" PRIu64 \" bytes)\\n\", data_bytes64);\n        fclose(f);\n        unlink(wav_path);\n        return -1;\n    }\n    uint32_t data_bytes = (uint32_t)data_bytes64;\n    uint32_t riff_size = 36 + data_bytes;\n    uint16_t fmt_code = 3;                // WAVE_FORMAT_IEEE_FLOAT\n    uint16_t bits_per_sample = 32;\n    uint16_t block_align = (uint16_t)(channels * sizeof(float));\n    uint32_t byte_rate = sample_rate * block_align;\n    uint16_t ch16 = (uint16_t)channels;\n    uint32_t fmt_size = 16;\n\n    fwrite(\"RIFF\", 1, 4, f);\n    fwrite(&riff_size, 4, 1, f);\n    fwrite(\"WAVEfmt \", 1, 8, f);\n    fwrite(&fmt_size, 4, 1, f);\n    fwrite(&fmt_code, 2, 1, f);","sourceCodeStart":1147,"sourceCodeEnd":1183,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L1147-L1183","documentation":"The generated audio exceeds the 4 GiB limit of 32-bit WAV. Guard: estimate samples*channels*bytes before encoding and either chunk the output or reject requests that exceed the WAV limit.","triggerScenarios":"Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:1165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Shorten the generated audio so the WAV stays under the 4 GiB 32-bit limit.","Split the output into multiple WAV files or use a 64-bit-capable format."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}